Bienvenue aux nouveaux arrivants sur FantasPic !

- Pensez à lire les règles durant votre visite, il n'y en a pas beaucoup, mais encore faut-il les respecter .
- N’hésitez pas à faire des remarques et/ou suggestions sur le Forum, dans le but de l'améliorer et de rendre vos prochaines visites plus agréables.
- Vous pouvez regarder votre "panneau de l'utilisateur" afin de configurer vos préférences.
- Un passage par "l'utilisation du forum" est recommandé pour connaître les fonctionnalités du forum.

--- L’équipe FantasPic ---
Forum général sur le langage C !

Modérateur : Jérémy

PIC27K42 et Interrupt On Change
paulfjujo
Avatar de l’utilisateur
Expert
Expert
Messages : 2589
Âge : 73
Enregistré en : juillet 2015
Localisation : 01800
Contact :

#1 Message par paulfjujo » mar. 5 janv. 2021 17:04

bonjour,

La poursuite des differentes fonctionalités offerte par ce PIC costaud, ici en version PDIP28 18F27K42 :

Interrupt On Change
Ce PIC permet de generer une interruption sur changement d'etat Front montant ou Descendant ou les 2
sur n'importe quelle PIN ( PORTA,B,C,E ) au lieu que du seul PORTB.

Pour la mise en oeuvre d'un tel test , il faut faire attention
à ne pas utiliser un Bouton Poussoir , qui génerera moultes interruptions ...à moins de bloquer la première qui arrive
mais je ne l'ai pas testé, vu que j'attaque l'entrée à tester : ici RA5 , via un montage hardware anti rebonds (bascule à 2 nands)
...derriere un boutons poussoir à 2 positions 1 ou 0
( faisant parti de mon (tres vieux) generateur BF à quartz ) !

Traduction partielle datasheet :
Extrait datasheet :
18.0 INTERRUPT-ON-CHANGE
Interruption sur changement d'etat sur n'importe quelle broche (Pin) d'un PORT.
18.1 Enabling the Module
Validation du registre PIEx pour permettre la generation d'une interruption sur une broche d'un PORT
le bit IOCIE correspondant du registre PIEx doit etre armé pour generer l'interruption.
Ceci n'empeche pas la detection de se faire ..
18.2 Individual Pin Configuration
Pour chaque pin de PORT, un detecteur de front Montant ou Descendant est présent
Pour valider une detection de front Montant sur une Pin , le bit associé du registre IOCxP (P comme Positif!) est mis à 1 .
Pour valider une detection de front Descendant sur une Pin , le bit associé du registre IOCxN (N comme Negatif!)est mis à 1 .
Une pin (broche) peut etre configuée en detection Front Montant ET Decendant , en armant (Mise à 1 ) le bit des 2 registres
correspondant IOCxP ET IOCxN
18.3 Interrupt Flags Drapeaux d'interruptions
les bits IOCAFx, IOCBFx, IOCCFx et IOCEF3 sont situés dans les registres respectifs IOCAF, IOCBF, IOCCF and IOCEF
leurs etats 0 ou 1 , reflete l'etat Interrupt On Change du PORT concerné.
Si un changement de front attendu est detecté sur la broche (Pin) validée en detection , le bit IOCIE est armé (mis à 1)
=> interruption autorisée
le bit IOCIF est aussi armé, il reflete l'etat de toutes le spin concernée sur les PORTS IOCAFx, IOCBFx,IOCCFx,IOCEF3_bit
18.4 Clearing Interrupt Flags RAZ des drapeaux
L'état individuel des drapeaux représentant les entrées du PORT (IOCAFx, IOCBFx, IOCCFx et IOCEF3 bits),
peut être respectivement remis à zéro .
Si une autre detection de front est detectée pendant la remise à zero,
le flag associé est à nouveau remis à un.
Pour s'assurer qu'aucun Front ne soit perdu , pendant la remise à zero du Flag ( en cours de traitement)
Seule une opération utilisant un MASQUE permettant d'isoler le(s) bit(s) connu comme ayant changé
doit être réalisée.
exemple de séquence :
MOVLW 0xff
XORWF IOCAF, W
ANDWF IOCAF, F
le test ci-dessus n'est pas convainquant ..pour ma part .
Bank probleme ?


je laisse les "ASM mens " à voir ce" betitProblem"

Diagram_InterruptOn_ChangePorta.B51.jpg


le suivi sur terminal, montre bien que seul le Front Montant RA5 est bien vu , capté via l'interruption IOC RA5.

Presentation :
Directory :C:\_MikroC\_MesProjets_MikroC\_18F27K42_Test_Interrupt_on_change_RA5
MikroC pro 7.60 Beta
Projet :Test_Interrupt_On_Change_18F27K42_2021.mcppi
Test PIC18F27K42 I2C
Config bit : P18F27K42_Fosc_Interne_64Mhz_with_RA6_Clockout.cfgsch
FOSC:64.0 MHz
Eeprom: not used ....
Source : PIC18F27K42_UART1_test_interrupt_On_Change_RA5__2021_0105.c
Rising Edge count on RA5= 0 RA5= 0
RA5= 0
RA5= 0
RA5= 0
RA5= 0
RA5= 0
RA5= 0
RA5= 1 Rising Edge occured on RA5 count= 1

RA5= 1

RA5= 1
RA5= 1
RA5= 1
RA5= 0
RA5= 0
RA5= 0
RA5= 1 Rising Edge occured on RA5 count= 2

RA5= 1

RA5= 1
RA5= 1
RA5= 1
RA5= 1
RA5= 1
RA5= 1
RA5= 1
RA5= 1

RA5= 1
RA5= 1
RA5= 0
RA5= 0
RA5= 1 Rising Edge occured on RA5 count= 3

RA5= 1
RA5= 1


nota : un saut de ligne est inséré toute les 8 valeurs de RA5

le programme MikroC 7.60

Code : Tout sélectionner

#define Version "2021_0105"
/*
CONFIG1L : $300000 : 0x0004
CONFIG1H : $300001 : 0x0028
CONFIG2L : $300002 : 0x00F5
CONFIG2H : $300003 : 0x00B7
CONFIG3L : $300004 : 0x001F
CONFIG3H : $300005 : 0x003F
CONFIG4L : $300006 : 0x009F
CONFIG4H : $300007 : 0x000F
CONFIG5L : $300008 : 0x0001
CONFIG5H : $300009 : 0x0000
*/ 
  
ac:IOC_explicage_

 
// Hardware
 /*
 Pin 28  RB7  --x  x----ICSP Data
 Pin 27  RB6  --x  x-----ICSP Clock
 Pin 26  RB5
 Pin 25  RB4
 Pin 24  RB3
 Pin 23  RB2
 Pin 22  RB1
 Pin 21  RB0
 Pin 20      VDD --------+5V
 Pin 19      Vss ---------Gnd          fil noir cable prolific
 Pin 18  RC7  RX UART  <-- Keyboard    fil Vert cable prolific
 Pin 17  RC6  TX UART  --> Display     fil Blanc cable prolific
 Pin 16  RC5

 Pin 15  RC4  SDA  I2C
 Pin 14  RC3  SCL  I2C

 Pin 13  RC2
 Pin 12  RC1
 Pin 11  RC0

 Pin 10  RA6
 Pin  9  RA7
 Pin  8  VSS ---------  Gnd
 Pin  7  RA5  <----input
 Pin  6  RA4  -----> led
 Pin  5  RA3
 Pin  4  RA2
 Pin  3  RA1
 Pin  2  RA0  <---- Analog Input
 Pin  1  RE3 MCLR  Reset <--------ICSP PGRM
                          |----x  x----/0V   cavalier RESET
 */


#define Directory "C:\\_MikroC\\_MesProjets_MikroC\\_18F27K42_Test_Interrupt_on_change_RA5"
#define Project "Test_Interrupt_On_Change_18F27K42_2021.mcppi"
#define Source  "PIC18F27K42_UART1_test_interrupt_On_Change_RA5_"
#define Eeprom " not used ...."
#define Config "P18F27K42_Fosc_Interne_64Mhz_with_RA6_Clockout.cfgsch"
#define PROCESSOR "18F27K42"
#define POWER_SUPPLY  " 3.6V"

#define OSCILLATEUR_INTERNE
#define FOSC "64.0"  // MHz
#define BAUD "19200"  // UART1

#define CLS 12
#define CR 13    //0x0D
#define LF 10
#define TAB 9
#define BACK 8
#define Beep 7
#define Separator 0x20   // space
#define ON 0    // because led tirée au +VCC
#define OFF 1
#define SPECIAL 1
#define NORMAL 0

#ifndef Byte
#define Byte unsigned char
#endif
#ifndef Word
#define Word unsigned int
#endif

const code char mesg0[]=" Directory :"Directory"\r\n";
const 
code char mesg1[]=" MikroC pro 7.60 Beta \r\n";
const 
code char mesg2[] =" Projet :"Project"\r\n";
const 
code char mesg3[]=" Test PIC18F27K42  I2C \r\n";
const 
char char mesg4[]=" Config bit : "Config"\r\n FOSC:"FOSC" MHz\r\n";
const 
char char mesg5[]=" Eeprom: "Eeprom"\r\n";
const 
char char mesg6[]=" Source : "Source"_"Version".c\r\n";
const 
char char mesg7[]=" Test interrupt On Change on RA5 input\r\n";
const 
char char mesg8[]=" Use of a special anti-bounce pulse generator to do only one pulse at time\r\n";
const 
char char mesg9[] =" ";
const 
char char mesg10[]=" ";
const 
code char Messages[]={mesg0,mesg1,mesg2,mesg3,mesg4,mesg5,mesg6,mesg7,mesg8,mesg9,mesg10};
const 
char Blancs[]="  ";

#define Word unsigned int
#define Byte unsigned char

sbit Led_Rouge at LATA.B4;
sbit Led_Rouge_Dir at TRISA.B4;
sbit SQA at LATA.B3;
sbit SQA_Dir at TRISA.B3;

#define MAX_LEN1 128
#define MAX_LEN2 80
#define MAX_LEN3 80

unsigned int i,j,k,l,m,n;
volatile unsigned char c1,cx;
char dummy=0;
char *p1;

unsigned char CRam1[MAX_LEN2];
unsigned char TEXTE [MAX_LEN3];
unsigned char *txt;


volatile signed int Cpt1;

int Status;
unsigned char Adr;
volatile int CountRA5;

void Init_Hardware(void) ;
void CRLF1(void) ;
void UART1_Write_CText(const char *txt);
void strConstRamCpy(unsigned char *dest, const code char *source);


void Interrupts() iv 0x0008 ics ICS_AUTO
{
   if ( (
IOCAF.B5==1) && (IOCIE_bit==1))
   {
     
IOCAF.B5=0;
     
LATA4_bit 1;
    
/*
    _asm{
      MOVLW 0xFF
      XORWF IOCAF, W
      ANDWF IOCAF, F
     }
     */
     
CountRA5++;
    
// IOCIE_bit=0;   // to catch only one Rising edge
    
}
}

#include "built_in.h"     // for  Hi  Lo ..etc
// --- Copie le texte depuis FLASH ROM vers RAM
void strConstRamCpy(unsigned char *dest, const code char *source)
 {
  while (*
source)*dest++ = *source++ ;
  *
dest ;    // terminateur
}

void CRLF1()
{
 
UART1_Write(CR); UART1_Write(LF);
}


void Print(char *txt)
 {
   while (*
txt)
      
UART1_Write(*txt++);
 }
 
 
void CPrint(const char *txt)
 {
   while (*
txt)
      
UART1_Write(*txt++);
 }

  
void UART1_Write_CText(const char *txt)
 {
   while (*
txt)
      
UART1_Write(*txt++);
 }



void Init_Hardware()
{
  
PORTA 0x00;
  
ANSELA=0x02;  // RA1 analog
  
TRISA 0b10100011 ;   // RA0 as OWS  ,RA1 as Analog  RA2,RA3,RA4,RA6 as output , RA5 & RA7 as  input
  
SLRCONA.B6=0// clockout 16Mhz
  
SQA=0;

  
ANSELB=0;
  
PORTB 0x00;
  
TRISB 0x00;    //  B0..B7 Output   ATTENTION B7 B6 for ICSP Pickit3
  
WPUB=0xFF;
  
CM1CON0=0;
  
CM2CON0=0;

  
PORTC=0;
  
ANSELC=;
  
TRISC 0b10000000;    //
  
FVRCON=0;
  
FVRCON.FVREN=1;  // page 597  paragraph 34.3
  
FVRCON.ADFVR1=1// 01 = Fixed Voltage Reference Peripheral output is 1,024)
  
FVRCON.ADFVR0=0;
   
SLRCONC=0x00;
  
}


 
void Init_FOSC(void)
 {

 
// REGISTER 7-5: OSCFRQ: HFINTOSC FREQUENCY SELECTION REGISTER
   // Frequence selection 64MHz
     
FRQ3_bit=1   ;
     
FRQ2_bit=0   ;
     
FRQ1_bit=0   ;
     
FRQ0_bit=0   ;
    
// REGISTER 7-6: OSCTUNE: HFINTOSC TUNING REGISTER
    
OSCTUNE=0;
    
//REGISTER 7-7: OSCEN: OSCILLATOR MANUAL ENABLE REGISTER
    
OSCEN=0;
    
// TABLE 7-1: NOSC/COSC AND NDIV/CDIV BIT SETTINGS pge 103
     // COSC  Clock Source = 110 = HF INTOSC = 64Mhz
     
OSCCON1.COSC2=1;
     
OSCCON1.COSC1=1;
     
OSCCON1.COSC0=0;
     
// NDIV <3:0>       0000 => 1/1   0001 => 1/2  0100 => 1/16
     
OSCCON1.NDIV3=0;   // 64=8Mhz
     
OSCCON1.NDIV2=0;
     
OSCCON1.NDIV1=0;
     
OSCCON1.NDIV0=0;
}


void main()
 {
    
Init_FOSC() ;  // 64 MHz
    
Init_Hardware();
    for (
i=0;i<MAX_LEN2;i++) CRam1[i]=0;
    
LATA.B4=1;

   
Unlock_IOLOCK()  ;
   
RC6PPS 0x13;   //RC6->UART1:TX1;
   
U1RXPPS 0x17;   //RC7->UART1:RX1;
   
Lock_IOLOCK() ;
  
    
UART1_Init(19200);
    
UART_Set_Active(&UART1_Read, &UART1_Write, &UART1_Data_Ready, &UART1_Tx_Idle); // set UART1 active
    
Delay_ms(1000);

    
UART1_Write(CLS);
    
CPrint("\r\n Presentation : \r\n");
    for (
i=0;i<7;i++)   CPrint(Messages[i]);

    
LATA4_bit 0;
    
CountRA5=0;
    
INLVLA.B5=1;  //1 = ST input used for port reads and interrupt-on-change
    
IOCAF=0;
    
IOCAP5_bit 1// Interrupt  ON rising edge RA5
    
IOCAN5_bit 0// no interrupt on Falling edge on RA5
    
IOCIF_bit 0;  // drapeau general  interrupt
    
IOCIE_bit 1;  //IOCIE: Interrupt-on-Change Enable bit
    
GIE_bit 1;
    
j=0;
    
WordToStr(CountRA5,CRam1);
    
CPrint(" Rising Edge count on RA5= ");
    Print(
CRam1);
    do
    {
     
// show the  status of RA5 input
    
CPrint(" RA5= ");
    
UART1_Write(PORTA.B5+48);
    
UART1_Write(TAB);
   if ((
j%8==0) &&( j>0))
    {
    
CRLF1(); // new empty line every 8 values
    
}
    if (
PORTA.B4==1)  // interrupt armed this bit !
    
{
      
CPrint(" Rising Edge occured on RA5  count= ");
       
WordToStr(CountRA5,CRam1);
      Print(
CRam1);
      
CRLF1();
        
LATA4_bit 0;
         
IOCIE_bit=1;  // re-arme interrupt for next test
         // so we have enough time to see what is happenning
     
}
    
CRLF1();
    
Delay_1sec();
    
j++;
    }
    while(
1);
}





pour quel usage, type d'application ?
clavier ?
start chronometre ?


A+
Vous n’avez pas les permissions nécessaires pour voir les fichiers joints à ce message.
Aide toi, le ciel ou FantasPic t'aidera

PIC27K42 et Interrupt On Change
Temps-x
Avatar de l’utilisateur
Expert
Expert
Messages : 2596
Enregistré en : juillet 2016
Localisation : Terre

#2 Message par Temps-x » mer. 6 janv. 2021 03:34

Bonsoir paulfjujo, et tout le forum,

paulfjujo a écrit :Source du message Traduction partielle datasheet :

Merci ! pour la traduction, :sifflotte: bon il te reste les 832 pages à traduire....

Je suis obliger d'avancer en traduisant page après page, c'est vraiment pas évident pour quelqu'un qui ne comprend pas l'anglais.


==> A+
:roll: Les requins, c'est comme le langage ASM, c'est le sommet de la chaîne alimentaire. :wink:


Retourner vers « Langage C »

Qui est en ligne

Utilisateurs parcourant ce forum : Aucun utilisateur enregistré et 41 invités