Ce code tourne pourtant...mais testé au milieu de MON programme..
un autre exemple complet, testé avec un 16F874,mais le code est le meme pour le 16F877..
Code:// test avec platine 16F874 + Nokia // 16F874 avec bootloader incorporé 10Mhz 19200 bauds // usage de Pic Downloader 1.09 pour transfert via bootloader du 16F874 #define LedRouge PORTE.F2 #define CLS 12 #define TAB 9 #define CR 13 #define LF 10 void Write_String(void); void CRLF(void); void Chenillard(void); void UART1_Write_CText(const char *txt); char *txt; unsigned char TEXTE[32]; unsigned int M; char outmode=0; char UnCar; unsigned int temp_res; void main() { int i,j,k; PORTB = 0x00; // set PORTB to FF TRISB = 0xFF; // designate portb pins as output PORTA = 0xFF; TRISA = 0xFF; // PORTA is RA0,1,2,3,4,5=input TRISE=0; PORTE=0xFF; TRISD=0x00; // all outputs PORTC = 0xFF; // set PORTC to $FF TRISC = 0xBF; UART1_Init(9600); // RS232 Delay_ms(1000); UART1_Write(CLS); // efface ecran VBRAY Delay_ms(1000); txt=TEXTE; // init pointeur txt txt= strcpy(txt,"Init UART 9600 bds.. OK "); Write_String(); CRLF(); UART1_Write_CText("ADC init\r\n "); //ADC_Init(); ADCON0 = 0x81; // ADON = 1, Channel A.0 select, Fosc/32 select ADCON1 = 0x8E; // 0x8E,0xC0 port a as analog, right justified output UART1_Write_CText("Attente saisie au clavier"); Write_String(); CRLF(); while(1) { UART1_Write_CText("ADC0 " ); temp_res=ADC_Read(0); txt=TEXTE; // init pointeur txt WordToStr(temp_res,txt); UART1_Write_Text(txt); UART1_Write(TAB); UART1_Write_CText("ADC1 " ); temp_res=ADC_Read(1); txt=TEXTE; // init pointeur txt WordToStr(temp_res,txt); UART1_Write_Text(txt); CRLF(); LedRouge=!LedRouge; if (UART1_Data_Ready()==1) { UnCar=UART1_Read(); UART1_Write (UnCar); UART1_Write (TAB); *(txt)=0; if (UnCar=='A') { UART1_Write_CText("Les LEDS sont OK "); Chenillard(); } if (UnCar=='X') { UART1_Write_CText("Le Moteur est OK "); Delay_ms(1800); } CRLF(); } Delay_ms(500); } //while } void Write_String() { short int i1,j1,k; j1=strlen(TEXTE); i1=0; do { k=TEXTE[i1]; UART1_Write(k); i1++; }while (i1<j1); } void CRLF() { UART1_Write(CR); UART1_Write(LF); } void Chenillard() { PORTD = 0; Delay_ms(150); PORTD = 1; Delay_ms(350); PORTD = 2; Delay_ms(350); PORTD = 3; Delay_ms(350); PORTD = 4; Delay_ms(350); PORTD = 5; Delay_ms(350); PORTD = 6; Delay_ms(350); PORTD = 5; Delay_ms(350); PORTD = 4; Delay_ms(350); PORTD = 3; Delay_ms(350); PORTD = 2; Delay_ms(350); PORTD = 1; Delay_ms(350); PORTD = 0; } void UART1_Write_CText(const char *txt) { while (*txt) UART1_Write(*txt++); } /* 0 1 mikroCPIC1618.exe -MSF -DBG -pP16F874 -GC -C -DL -O11111115 -fo10 -N"C:\_MickroC\_MesProjets_MickroC\_16F877_Platine\16F874_Platine_Nokia_RS.mcppi" -SP"C:\Program Files\Mikroelektronika\mikroC PRO for PIC\defs\" -SP"C:\Program Files\Mikroelektronika\mikroC PRO for PIC\Uses\P16\" -SP"C:\_MickroC\_MesProjets_MickroC\_16F877_Platine\" -SP"C:\_MickroC\_MesProjets_MickroC\_Nokia_LCD\" "16F874_Test_RS232.c" "__Lib_Math.mcl" "__Lib_MathDouble.mcl" "__Lib_System.mcl" "__Lib_Delays.mcl" "__Lib_CType.mcl" "__Lib_CString.mcl" "__Lib_CStdlib.mcl" "__Lib_Conversions.mcl" "__Lib_Sprinti.mcl" "__Lib_SoftI2C.mcl" "__Lib_ADC_A_C.mcl" "__Lib_UART_c67.mcl" 0 1139 Available RAM: 176 [bytes], Available ROM: 4096 [bytes] 0 126 All files Preprocessed in 31 ms 0 122 Compilation Started 16F874_Test_RS232.c 41 1509 Generated baud rate is 18939 bps (error = 1.36 percent) 16F874_Test_RS232.c 24 1163 Variable 'i' has been declared, but not used 16F874_Test_RS232.c 24 1163 Variable 'j' has been declared, but not used 16F874_Test_RS232.c 24 1163 Variable 'k' has been declared, but not used 16F874_Test_RS232.c 144 123 Compiled Successfully 16F874_Test_RS232.c 94 1164 Variable 'k' has been eliminated by optimizer 16F874_Test_RS232.c 0 127 All files Compiled in 110 ms 0 1144 Used RAM (bytes): 71 (40%) Free RAM (bytes): 105 (60%) Used RAM (bytes): 71 (40%) Free RAM (bytes): 105 (60%) 0 1144 Used ROM (program words): 852 (21%) Free ROM (program words): 3244 (79%) Used ROM (program words): 852 (21%) Free ROM (program words): 3244 (79%) 0 125 Project Linked Successfully 16F874_Platine_Nokia_RS.mcppi 0 1004 COFF file successfully generated COFF file successfully generated 0 128 Linked in 515 ms 0 129 Project '16F874_Platine_Nokia_RS.mcppi' completed: 734 ms 0 103 Finished successfully: 17 juin 2014, 18:34:06 16F874_Platine_Nokia_RS.mcppi */
le resultat capturé sur l'ecran
****** resultats ***********
Init UART 1200 bds.. OK
ADC init
Attente saisie au clavierInit UART 1200 bds.. OK
ADC0 793 ADC1 0
ADC0 793 ADC1 0
ADC0 793 ADC1 0
ADC0 793 ADC1 0
ADC0 793 ADC1 0
ADC0 793 ADC1 55
ADC0 793 ADC1 441
ADC0 793 ADC1 613
ADC0 793 ADC1 908
ADC0 793 ADC1 1023
ADC0 793 ADC1 1023
ADC0 793 ADC1 1021
ADC0 793 ADC1 701
ADC0 793 ADC1 542
ADC0 793 ADC1 466
ADC0 793 ADC1 413
ADC0 793 ADC1 329
ADC0 793 ADC1 80
ADC0 793 ADC1 74
X Le Moteur est OK
ADC0 793 ADC1 74
ADC0 793 ADC1 74
ADC0 793 ADC1 73
ADC0 793 ADC1 74
ADC0 793 ADC1 73
ADC0 793 ADC1 74
ADC0 793 ADC1 73
A Les LEDS sont OK
ADC0 793 ADC1 74
ADC0 793 ADC1 73
ADC0 793 ADC1 74
ADC0 793 ADC1 73
-----