#define LEDBlue PORTEbits.RE0 // donne un nom explicite au bit n°0 du port E TRISE = 0xFFFE; // définit la direction des ports : RE0 Output LED, RE1 à RE8 input PORTEbits.RE0=1; // ligne équivalente à LEDBlue=1; // met le bit à 1 donc VDD (5V ou 3V) sur la pin RE0 |
#define ToucheRUN PORTEbits.RE1 // donne un nom explicite au bit n°1 du port E #define LEDBlue PORTEbits.RE0 // donne un nom explicite au bit n°0 du port E TRISE = 0xFFFE; // définit la direction des ports : RE0 Output LED, RE1 à RE8 input if (ToucheRUN) LEDBlue=1; // Allume la LED si la touche est appuyée // ligne équivalente à if (PORTEbits.RE1) PORTEbits.RE0=1; // Allume la LED si la touche est appuyée |
PORTGbits.RG0 = 1; PORTGbits.RG1 = 0; |
LATGbits.LATG0 = 1; LATGbits.LATG1 = 0; |
Etatreel = PORTGbits.RG2 |
PORTGbits.RG2 |
_RG2 |
LATBbits.LATB2 |
_LATB2 |
#define ToucheRUN _RE1 // donne un nom explicite au bit n°1 du port E #define LEDBlue _LATE0 // donne un nom explicite au bit n°0 du port E TRISE = 0xFFFE; // définit la direction des ports : RE0 Output LED, RE1 à RE8 input if (ToucheRUN) LEDBlue=1; // Allume la LED si la touche est appuyée |
// config ADC en lancement immédiat ADCON1 = 0x800 C; //Conv continously, 4 ch simultanés, ADC Off for configuring ADCON2 = 0x0200; // simulataneous sample 4 channels ADCHS = 0x0022; // Connect RB2/AN2 as CH0 = pot K_V_f AN3/RB3 to CH1 = pot Fs ADCON3 = 0x0080; // Tad = internal RC (4uS) ADCON1bits.ADON = 1; // turn ADC ON //... ADCON1bits.SAMP = 0; // start conversion while(!ADCON1bits.DONE) {} // attend la fin CMPR=ADCBUF0; |
void InitADC10(void) { ADPCFG = 0xFFC3; // all PORTB = Digital(1) ;RB2 to RB5 = analog(0) ie 1100 0011 ADCON1 = 0x006F; // PWM starts conversion, 4 ch simultanés, ADC Off for configuring ADCON2 = 0x0200; // simulataneous sample 4 channels, ADC INTerrupt à chaque EOC=100 us ADCHS = 0x0022; // AN2/RB2 Ch0 Vref, AN3/RB3 Ch1 Vmes, AN4/RB4 Ch2 Vreflimiteur, AN5/RB5 Ch3 NC ADCON3 = 0x0080; // Tad = internal RC (4uS) IFS0bits.ADIF = 0; // Adc int flag Off IEC0bits.ADIE = 1; // Adc int On ADCON1bits.ADON = 1; // turn ADC ON } //--------------------------------------------------------------------- // The ADC interrupt reads the demand pot value. // tt est synchrone % à cette int de ADC int =2*PWMperiod=2*62.5 us=125 us //--------------------------------------------------------------------- void __attribute__((__interrupt__)) _ADCInterrupt (void) { InterruptLED=1; // pour visualiser sur oscillo le tps d exécution de la routine IFS0bits.ADIF = 0; Vref=ADCBUF0; // 0 à 1023 ie 0 à 0x3FF Vmes=ADCBUF1; Vreflimiteur=ADCBUF2; //.... InterruptLED=0; } //------------------------------------------------------------------------ |
//Configuration bits // Q=7.3728 MHz _FOSC(CSW_FSCM_OFF & XT_PLL16); // 7.3728MHz *16 = 117.9648 MHz /4 = 29.4912 MIPS maxi pour ce pic _FWDT(WDT_OFF); _FBORPOR(PBOR_OFF & BORV_27 & PWRT_16 & MCLR_EN); _FGS(CODE_PROT_OFF); //----------------------------------------------------------------------------- // Program Specific Constants #define FCY 29491200 // Instruction cycle rate (Osc x PLL / 4) #define FPWM 16000 // PWM freq #define HalfDUTY 921 // set the pwm half duty = PTPER = 920.6 =FCY/FPWM/2-1; #define FullDUTY HalfDUTY*2 // car PDCx a une double resolution % PTPER #define MILLISEC FCY/29491 // 1 mSec delay constant #define DS_PoszReg 100 // Compteur pour la regulation 100* 125us = 12.5 ms #define InterruptLED LATBbits.LATB0 // Output #define InfoLED PORTBbits.RB1 // Output #define RunningLED LATDbits.LATD1 // Output #define StartRegul PORTDbits.RD0 // Input // BP2 pour commencer StartRegul // Enable surles PWM low #define L298_p_Enable PORTEbits.RE0 // la pin PWM1 low utilisé en Enable du L298 #define L298_alpha_Enable PORTEbits.RE2 // la pin PWM2 low ! #define L298_beta_Enable PORTEbits.RE4 // la pin PWM3 low ! // l inhib PWM se fait aussi par cavalier sur la carte //----------------------------------------------------------------------------- // Setup ports //----------------------------------------------------------------------------- void setup_ports(void) { // Clear All Ports Prior to defining I/O PORTB=0; //Initialize LED pin data to off state PORTC=0; PORTD=0; PORTE=0; // Now set pin direction registers TRISB = 0xFFFC; // RB0 interruptLED, RB1 InfoLED output, RB2-5 inputs : ADC RB2-5 TRISC = 0xDFFF; // U1ATX/RC13 in , U1ATX/RC14 out TRISD = 0xFFFD; // RunningLED RD1 Output , StartPrg RD0 Input TRISE = 0x01C0; // RE1, RE3, RE5 are the PWMs -> outputs les low : RE4, RE2, RE0 : L298 Enable output, RE8 input TRISF = 0xFFFF; // RF NC input } //----------------------------------------------------------------------------- // Setup the ADC registers for : // 4 channels conversion // PWM trigger starts conversion // AD interrupt is set and buffer is read in the interrupt //----------------------------------------------------------------------------- void InitADC10(void) { ADPCFG = 0xFFC3; // all PORTB = Digital(1) ;RB2 to RB5 = analog(0) ie 1100 0011 ADCON1 = 0x006F; // PWM starts conversion, 4 ch simultanés, ADC Off for configuring ADCON2 = 0x0200; // simulataneous sample 4 channels, ADC INTerrupt à chaque EOC=100 us ADCHS = 0x0022; // AN2/RB2 Ch0 Bref, AN3/RB3 Ch1 Bmes, AN4/RB4 Ch2 NC, AN5/RB5 Ch3 NC ADCON3 = 0x0080; // Tad = internal RC (4uS) IFS0bits.ADIF = 0; // Adc int flag Off IEC0bits.ADIE = 1; // Adc int On ADCON1bits.ADON = 1; // turn ADC ON } //----------------------------------------------------------------------------- // InitMCPWM, intializes the PWM as follows: // FPWM = 16 khz voir en haut // Independant PWMs // Set ADC to be triggered by PWM special trigger //----------------------------------------------------------------------------- void InitMCPWM(void) { PTPER = HalfDUTY; // set the pwm period register, ne pas oublier la double précision PWMCON1 = 0x0770; // enable PWMs tt le tps PDC1=HalfDUTY; PDC2=HalfDUTY; PDC3=HalfDUTY; // init sans rien, apres une regul ça change L298_p_Enable=0; // disable L298 principal L298_alpha_Enable=0; // disable L298 alpha L298_beta_Enable=0; // disable L298 beta OVDCON = 0xFFFF; // Cmde MLI, no effect of OVDCON SEVTCMP = PTPER; // set ADC to trigeer at ... PWMCON2 = 0x0000; // 1 PWM values PTCON = 0x8002; // start PWM symetrique } //--------------------------------------------------------------------- // The ADC interrupt reads the demand pot value. // tt est synchrone % à cette int de ADC int =2*PWMperiod=2*62.5 us=125 us //--------------------------------------------------------------------- void __attribute__((__interrupt__)) _ADCInterrupt (void) { InterruptLED=1; // InfoLED=1; IFS0bits.ADIF = 0; Bref=ADCBUF0; // max 1023 Bmes=ADCBUF1; Vreflimiteur=ADCBUF2; fs=(ADCBUF3-512)<<3; // 4.12 pu 4096=1.0=20 Hz if (Vreflimiteur>HalfDUTY) Vreflimiteur=HalfDUTY; // jusquà 624 Vrefmax=FullDUTY-Vreflimiteur; // si RefI=0 alors pleine puissance autorisée Vrefmin=Vreflimiteur; // reg PI // exécute toutes les DS_PoszReg (100) * fois if ( ++countReg==DS_PoszReg ) { countReg=0; // regul angle e=Bref-Bmes; // erreur à forcer à zéro Vref =Kp_reg*e + xe_reg + Kd_reg*(e-Olde) + HalfDUTY; // if ( Vref>Vrefmin && Vref<Vrefmax ) xe_reg += Ki_reg*e; xe_reg += Ki_reg*e; if (xe_reg<-FullDUTY) xe_reg=-FullDUTY; if (xe_reg>FullDUTY) xe_reg=FullDUTY; if (Vref<Vrefmin) Vref=Vrefmin; if (Vref>Vrefmax) Vref=Vrefmax; Olde=e; // mise à jour du rapport cyclique PDC1=Vref; // bobine principale } // tensions pour faire tourner, s exécute tte les ADC int =2*PWMperiod=2*62.5 us=125 us thetasinc=__builtin_mulss(Ktheta,fs)>>12; thetas+=thetasinc; sinthetas=SinusTable[thetas>>8]; costhetas=SinusTable[((thetas>>8)+64) & 255]; // debug Vds=Vrefmax; Valphas=__builtin_mulss(Vds,costhetas)>>12; Vbetas =__builtin_mulss(Vds,sinthetas)>>12; tmp1=+(__builtin_mulss(ByEs2,Valphas))>>12; PDC2=HalfDUTY+tmp1; tmp1=(__builtin_mulss(ByEs2,Vbetas))>>12; PDC3=HalfDUTY+tmp1; // debug PDC2=HalfDUTY; // bobine alpha PDC3=HalfDUTY; // bobine beta // communication dsPIC -> PC if (!--SeqComm) { SeqComm=SeqCommMax; Flags.SendData=1; } InterruptLED=0; } //------------------------------------------------------------------------ |
#include "p30F3010.h" //Configuration bits /// Qartz de 10 MHz _FOSC(CSW_FSCM_OFF & XT_PLL8); //10Mhz *8 = 80 MHz /4 = 20 MIPS maxi pour ce pic _FWDT(WDT_OFF); _FBORPOR(PBOR_OFF & BORV_27 & PWRT_16 & MCLR_EN); _FGS(CODE_PROT_OFF); //----------------------------------------------------------------------------- //Program Specific Constants #define FCY 20000000 //Instruction cycle rate (Osc x PLL / 4) = 20 MIPS #define T1Period 4000 // pour 200us à 20 MHz = T1Period = 4000=FCY*200us #define tcntPRD 500 // combien de fois pour ariver en Te=0.1s avec des pas de 200us : 500 //----------------------------------------------------------------------------- // intitialise timer 1 et l interruption //----------------------------------------------------------------------------- void initTimer(void) { // Timer1 pour l ISR des 100 us T1CON = 0; // ensure Timer 1 is in reset state, internal timer clock Fosc/4, no prescale TMR1 = 0; // RAZ Timer1 IFS0bits.T1IF = 0; // reset Timer 1 interrupt flag IPC0bits.T1IP = 4; // set Timer1 interrupt priority level to 4 IEC0bits.T1IE = 1; // enable Timer 1 interrupt PR1 = T1Period; // set Timer 1 period register T1CONbits.TON = 1; // enable Timer 1 and start the count } //----------------------------------------------------------------------------- // Timer1 interrupt fait le calcul et l allumage des LED // ISR toutes les 200 us //--------------------------------------------------------------------- void __attribute__((__interrupt__)) _T1Interrupt( void ) { IFS0bits.T1IF = 0; if (++tcnt>=tcntPRD) {// ici on est toutes les secondes tcnt=0; TimeStamp++; if (++Sec==60) { Sec=0; if (++Min==60) { Min=0; if (++Hour==24) Hour=0; } } sprintf(LCDbuffer, "Il est :"); LCD3310_GotoXY(0,1); LCD3310_SendMsg(LCDbuffer); sprintf(LCDbuffer, "%02d:%02d:%02d",Hour, Min, Sec); LCD3310_GotoXY(0,2); LCD3310_SendMsg(LCDbuffer); } } //----------------------------------------------------------------------------- |
// RS232 ------------------------------------------- unsigned char *TXPtr; unsigned char *RXPtr; void InitUART(void); void SendMsg(void); #define CR 0x0D #define LF 0x0A #define BAUD 19200 #define OffsetTimeStamp 10 // offset in OutData : position de la val de TimeStamp unsigned char InData[] = {"000000"}; unsigned char OutData[] = {"TimeStamp=0000 Ssr0_T=0000\r\n"}; int SeqComm; // ttes les 0.5 s #define SeqCommMax 5000 //--------------------------------------------------------------------- // Below are the interrupt vectors for the serial receive and transmit //--------------------------------------------------------------------- void __attribute__((__interrupt__)) _U1TXInterrupt(void) { IFS0bits.U1TXIF = 0; // clear interrupt flag } //--------------------------------------------------------------------- void __attribute__((__interrupt__)) _U1RXInterrupt(void) { IFS0bits.U1RXIF = 0; // clear interrupt flag *RXPtr = U1RXREG; if (*RXPtr == CR) {Flags.CheckRX = 1; RXPtr = &InData[0];} else *RXPtr++; } //------------------------------------------------------------------------ // Transmission over serial void InitUART(void) { // Initialize the UART1 for BAUD = 19,200 U1MODE = 0x8400; // enable + alternate pins // U1MODE = 0x8000; // enable + normal pins U1STA = 0x0000; U1BRG = ((FCY/16)/BAUD) - 1; // set baud to 19200 IEC0bits.U1RXIE = 1; // enable RX interrupt RXPtr = &InData[0]; // point to first char in receive buffer Flags.CheckRX = 0; // clear rx and tx flags Flags.SendTX = 0; Flags.SendData = 0; // clear flag SeqComm=SeqCommMax; U1STAbits.UTXEN = 1; // Initiate transmission } //---------------------------------------------------- // Convertit un "Word" hexa en "4 chars Hexadécimaux" // et les sort sur la table en memoire //---------------------------------------------------- inline void ConvHexa(int Var, int tablePos, unsigned char * table) { int tmp; tmp=Var & 0x000F; if (tmp<=9) tmp+=0x30; else tmp+=0x37; table[tablePos+3]=tmp; tmp=Var>>4 & 0x000F; if (tmp<=9) tmp+=0x30; else tmp+=0x37; table[tablePos+2]=tmp; tmp=Var>>8 & 0x000F; if (tmp<=9) tmp+=0x30; else tmp+=0x37; table[tablePos+1]=tmp; tmp=Var>>12 & 0x000F; if (tmp<=9) tmp+=0x30; else tmp+=0x37; table[tablePos]=tmp; } //---------------------------------------------------- // Convertit un "12 bits" en "4 chars décimaux. 2 chars" xxxx.xx // maximum : 1023.75 pour 12 bits // et les sort sur la table en memoire //---------------------------------------------------- inline void ConvDec(int Var, int tablePos, unsigned char * table) { unsigned int k; unsigned char c; // Char k = Var>>2; c = k/1000; if (c > 0) k = k - c*1000; table[tablePos] =(c + 0x30); c = k/100; if (c > 0) k = k - c*100; table[tablePos+1]=(c + 0x30); c = k/10; if (c > 0) k = k - c*10; table[tablePos+2]=(c + 0x30); table[tablePos+3]=(char)(k + 0x30); // apres la virgule : switch (Var & 0x03) { case 0 : table[tablePos+5]=0x30; // xxxx.00 table[tablePos+6]=0x30; break; case 1 : table[tablePos+5]=0x32; // xxxx.25 table[tablePos+6]=0x35; break; case 2 : table[tablePos+5]=0x35; // xxxx.50 table[tablePos+6]=0x30; break; case 3 : table[tablePos+5]=0x37; // xxxx.75 table[tablePos+6]=0x35; break; } } //----------------------------------------------------------------------------- void SendMsg(void) { while (*TXPtr) { while (U1STAbits.UTXBF); U1TXREG = *TXPtr++; } } //------------------------------------------------------------------------ // SendData sends the debug information on the uart at 19200 baud void SendData() { // Codage ASCII de la donnée hexa ConvHexa( TimeStamp, OffsetTimeStamp, OutData); // TimeStamp en Hexa // Sensor0_Tr=(Sensor0_T >> 3) & 0xFFF; // ConvDec( Sensor0_Tr, OffsetSensor0_Tr, OutData); // Sensor0_T en Hexa TXPtr = &OutData[0]; SendMsg(); } //------------------------------------------------------------------------ //----------------------------------------------------------------------------- // Timer1 interrupt fait le calcul et l allumage des LED // ISR toutes les 200 us //--------------------------------------------------------------------- void __attribute__((__interrupt__)) _T1Interrupt( void ) { IFS0bits.T1IF = 0; ... ... ... // communication dsPIC -> PC if (!--SeqComm) { SeqComm=SeqCommMax; Flags.SendData=1; } } //Main routine int main(void) { unsigned int j; setup_ports(); InitVar(); InitUART(); initTimer(); while(1) { if (Flags.SendData) { SendData(); // send present fs serially Flags.SendData = 0; // clear flag } } // end of while (1) } |
//----------------------------------------------------------------------------- // Mise en oeuvre de l ecran LCD du Nokia 3310 // transmission par SPI, debug sur UART1 MAX3233E // dsPIC 30F3010 // L. BAGHLI 10/03/2007 int Timer1 200 us //----------------------------------------------------------------------------- #include "p30F3010.h" //Configuration bits /// Q=10 MHz _FOSC(CSW_FSCM_OFF & XT_PLL8); //10Mhz *8 = 80 MHz /4 = 20 MIPS maxi pour ce pic _FWDT(WDT_OFF); _FBORPOR(PBOR_OFF & BORV_27 & PWRT_16 & MCLR_EN); _FGS(CODE_PROT_OFF); //----------------------------------------------------------------------------- //Program Specific Constants #define FCY 20000000 //Instruction cycle rate (Osc x PLL / 4) = 20 MIPS #define T1Period 4000 // pour 200us à 20 MHz = T1Period = 4000=FCY*200us #define tcntPRD 500 // combien de fois pour ariver en Te=0.1s avec des pas de 200us : 500 #define MILLISEC FCY/20000 // 1 mSec delay constant typedef enum { LCD_CMD = 0, LCD_DATA = 1 } LcdCmdData; #define InterruptLED LATBbits.LATB0 // Output #define LCD3310_RST LATBbits.LATB1 // Reset InfoLED #define LCD3310_CS LATDbits.LATD0 // LCD3310 Chip select #define SPI_8bitsdelay 20 #define LCD3310_DC LATDbits.LATD1 // LCD3310 Data /Command mode select #define LCD3310_Speaker LATEbits.LATE5 // PWM speaker #include "font.h" void setup_ports(void); void DelayNmSec(unsigned int N); void InitVar(); void initTimer(); void InitSPI_LCD3310(); void LCD3310_Clear(); void LCD3310_GotoXY(unsigned short xnokia, unsigned short ynokia); void LCD3310_WriteChar(char ascii_code); void LCD3310_SendMsg(char *dataPtr ); void LCD3310_Send(unsigned short data, unsigned short cd ); char Phrase[]="Lotfi is here"; char LCDbuffer[100]; struct { unsigned Running : 1; unsigned CheckRX : 1; unsigned SendTX : 1; unsigned SendData : 1; unsigned unused : 12; } Flags; unsigned int tcnt, TimeStamp;; unsigned int Hour, Min, Sec; //----------------------------------------------------------------------------- // Initialise variables //----------------------------------------------------------------------------- void InitVar(void) { tcnt=0; TimeStamp=0; } //----------------------------------------------------------------------------- // Setup ports //----------------------------------------------------------------------------- void setup_ports(void) { // Clear All Ports Prior to defining I/O PORTB=0; //Initialize LED pin data to off state PORTC=0; PORTD=0; PORTE=0; // Now set pin direction registers TRISB = 0xFFFC; // RB0 interruptLED, LCD3310_RST / RB1 output, RB2-4 NC inputs 1111|1100 TRISC = 0xDFFF; // U1ATX/RC13 in , U1ATX/RC14 out , inutile pour le UART donc 0xFFFF is also ok TRISD = 0xFFFC; // LCD3310_CS / RD0 out, LCD3310_DC / RD1 out TRISE = 0x0000; // RE0-RE5 : out, RE5 PWM LCD3310_Speaker LCD3310_RST=1; // pas de RST LCD LCD3310_CS = 1; // Set SPI CS pin du LCD 3310 non actif LCD3310_DC = 0; // Enter Data Mode TRISF = 0xFFFB; // SDI1/RF2 in, SDO1/RF3 out 1011, inutile pour le SPI donc 0xFFFF is ok } //----------------------------------------------------------------------------- // Config // Init SPI du LCD //----------------------------------------------------------------------------- void InitSPI_LCD3310() { // SPI1CON = 0x0023; // Master mode, SCK = Fcy/8 = 2.5 MHz, CKP=0, CKE=0, Clk idle is low, 8 bits // SPI1CON = 0x0063; // Master mode, SCK = Fcy/8 = 2.5 MHz, CKP=1, CKE=0, Clk idle is low, 8 bits // SPI1CON = 0x0163; // Master mode, SCK = Fcy/8 = 2.5 MHz, CKP=1, CKE=1, Clk idle is low, 8 bits SPI1CON = 0x0123; // Master mode, SCK = Fcy/8 = 2.5 MHz, CKP=0, CKE=1, Clk idle is low, 8 bits // SPI1CON = 0x012E; // Master mode, SCK = Fcy/5/4 = 1.0 MHz |1110), CKP=0, CKE=1, Clk idle is low, 8 bits // SPI1CON = 0x006E; // Master mode, SCK = Fcy/5/4 = 1.0 MHz |1110), CKP=1, CKE=0, Clk idle is low, 8 bits // SPI1CON = 0x002E; // Master mode, SCK = Fcy/5/4 = 1.0 MHz |1110), CKP=0, CKE=0, Clk idle is low, 8 bits SPI1STAT = 0x8000; // Enable SPI port LCD3310_Send( 0x21, LCD_CMD ); // LCD Extended Commands. LCD3310_Send( 0xC8, LCD_CMD ); // Set LCD Vop (Contrast). LCD3310_Send( 0x06, LCD_CMD ); // Set Temp coefficent. LCD3310_Send( 0x13, LCD_CMD ); // LCD bias mode 1:48. LCD3310_Send( 0x20, LCD_CMD ); // LCD Standard Commands, Horizontal addressing mode. LCD3310_Send( 0x0C, LCD_CMD ); // LCD in normal mode. // LCD3310_Send( 0x0D, LCD_CMD ); // LCD in inverse videoe. } //--------------------------------------------------------------------- // Set the current position for data (x = 0->83, y = 0->5) void LCD3310_Clear() { unsigned int x, y; for (y=0; y<6; y++) for (x=0; x<84; x++) LCD3310_Send( 0x00, LCD_DATA ); // caractère vide } //--------------------------------------------------------------------- // Set the current position for data (x = 0->83, y = 0->5) void LCD3310_GotoXY(unsigned short xnokia, unsigned short ynokia) { LCD3310_Send( 0x40 | ( ynokia & 0x07), LCD_CMD ); // new y cursor position LCD3310_Send( 0x80 | ( xnokia & 0x7f), LCD_CMD ); // new x cursor position } //----------------------------------------------------------------------------- // Affiche un caractere à l écran void LCD3310_WriteChar(char ascii_code) { //20+ascii_code if (ascii_code<0x20) return; LCD3310_Send( FontLookup [ascii_code-0x20][0], LCD_DATA ); // bout de char LCD3310_Send( FontLookup [ascii_code-0x20][1], LCD_DATA ); // bout de char LCD3310_Send( FontLookup [ascii_code-0x20][2], LCD_DATA ); // bout de char LCD3310_Send( FontLookup [ascii_code-0x20][3], LCD_DATA ); // bout de char LCD3310_Send( FontLookup [ascii_code-0x20][4], LCD_DATA ); // bout de char } //----------------------------------------------------------------------------- void LCD3310_SendMsg(char *dataPtr ) { while ( *dataPtr ) LCD3310_WriteChar( *dataPtr++ ); } //----------------------------------------------------------------------------- // Affiche un caractere à l écran void LCD3310_Send(unsigned short data, unsigned short cd ) { unsigned int uidummy; if (cd==LCD_DATA) LCD3310_DC = 1; // Enter Data Mode else LCD3310_DC = 0; // Enter Command Mode SPI1STATbits.SPIROV = 0; // Clear overflow flag LCD3310_CS = 0; // Set SPI CS pin du LCD 3310 actif uidummy = SPI1BUF; // Read buffer to avoid overflow SPI1BUF=data; while (SPI1STATbits.SPITBF); while ( !SPI1STATbits.SPIRBF); // char LCD3310_CS = 1; // Set SPI CS pin du LCD 3310 non actif } //----------------------------------------------------------------------------- // intitialise timer 1 et l interruption //----------------------------------------------------------------------------- void initTimer(void) { // Timer1 pour l ISR des 100 us T1CON = 0; // ensure Timer 1 is in reset state, internal timer clock Fosc/4, no prescale TMR1 = 0; // RAZ Timer1 IFS0bits.T1IF = 0; // reset Timer 1 interrupt flag IPC0bits.T1IP = 4; // set Timer1 interrupt priority level to 4 IEC0bits.T1IE = 1; // enable Timer 1 interrupt PR1 = T1Period; // set Timer 1 period register T1CONbits.TON = 1; // enable Timer 1 and start the count } //----------------------------------------------------------------------------- // Timer1 interrupt fait le calcul et l allumage des LED // ISR toutes les 200 us //--------------------------------------------------------------------- void __attribute__((__interrupt__)) _T1Interrupt( void ) { IFS0bits.T1IF = 0; if (++tcnt>=tcntPRD) {// ici on est toutes les secondes tcnt=0; TimeStamp++; if (++Sec==60) { Sec=0; if (++Min==60) { Min=0; if (++Hour==24) Hour=0; } } InterruptLED=1; sprintf(LCDbuffer, "Il est :"); LCD3310_GotoXY(0,1); LCD3310_SendMsg(LCDbuffer); sprintf(LCDbuffer, "%02d:%02d:%02d",Hour, Min, Sec); LCD3310_GotoXY(0,2); LCD3310_SendMsg(LCDbuffer); InterruptLED=0; } } //Main routine int main(void) { unsigned int j; setup_ports(); LCD3310_RST=1; // ziada DelayNmSec(2000); LCD3310_RST=0; // Reset LCD DelayNmSec(1800); LCD3310_RST=1; // pas de RST LCD InitGeneral_LCD3310(); InitSPI_LCD3310(); LCD3310_Clear(); LCD3310_GotoXY(0,0); LCD3310_SendMsg(Phrase); //------------------------- InitVar(); InitUART(); initTimer(); while(1) { } // end of while (1) } |
char LCDbuffer[100]; sprintf(LCDbuffer, "%02d:%02d:%02d",Hour, Min, Sec); // à remplacer par : char LCDbufferTmp[]="xx:xx:xx"; print_heure_LCDbuffer(); //------------------------------------------------------------------------ // Converti Hour, Min, Sec en ASCII sur LCDbuffer void print_heure_LCDbuffer() { unsigned int k; unsigned char c; // Codage ASCII de la donnée k = Hour; c = k/10; if (c > 0) k = k - c*10; LCDbufferTmp[0] = (c + 0x30); LCDbufferTmp[1] = (char)(k + 0x30); k = Min; c = k/10; if (c > 0) k = k - c*10; LCDbufferTmp[3] = (c + 0x30); LCDbufferTmp[4] = (char)(k + 0x30); k = Sec; c = k/10; if (c > 0) k = k - c*10; LCDbufferTmp[6] = (c + 0x30); LCDbufferTmp[7] = (char)(k + 0x30); } |
|
|
Interface série (UART 0V / 5V) vers RS232 (9V / -9V). |
Connectique pour le programmateur / debugger ICD2. |
Last update : 25/09/2009