Salam,
J'ai fait un programme qui permet de récupérer une tension par la commande 0025H et recevoir une valeur phase voltage Ua entre 0 et 99999 (de type Word) via RS485 avec un pic 18F2550 ,
Qui peut me donner son avis !
Ci joint le Schéma sur isis et le programme pic :
_______
Code:#include <18F2550.h> #FUSES NOWDT //No Watch Dog Timer #FUSES HS //Internal Oscillator, HS used by USB #FUSES NOPROTECT //Code not protected from reading #FUSES NOBROWNOUT //Reset when brownout detected #FUSES NOPUT //No Power Up Timer #FUSES NOCPD //No EE protection #FUSES NOSTVREN //Stack full/underflow will cause reset #FUSES NODEBUG //No Debug mode for ICD #FUSES NOLVP //Low Voltage Programming on B3(PIC16) or B5(PIC18) #FUSES NOWRT //Program memory not write protected #FUSES NOWRTD //Data EEPROM not write protected #FUSES NOIESO //Internal External Switch Over mode enabled #FUSES NOFCMEN //Fail-safe clock monitor enabled #FUSES NOPBADEN //PORTB pins are configured as analog input channels on RESET #FUSES NOWRTC //configuration not registers write protected #FUSES NOWRTB //Boot block not write protected #FUSES NOEBTR //Memory not protected from table reads #FUSES NOEBTRB //Boot block not protected from table reads #FUSES NOCPB //No Boot Block code protection #FUSES MCLR //Master Clear pin enabled #FUSES NOLPT1OSC //Timer1 configured for low-power operation #FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode) #FUSES PLL1 //No PLL PreScaler #use delay(clock=20000000) #use rs232(baud=9600,parity=N,xmit=PIN_c1,rcv=PIN_c2,bits=8) #define RS485_ENABLE_PIN PIN_A3 #define use_portb_lcd=1 #include "lcd.C" char timed_getc() { long timeout; int timeout_error; timeout_error=FALSE; timeout=0; while(!kbhit()&&(++timeout<50000)) // 1/2 // second delay_us(10); if(kbhit()) return(getc()); else { timeout_error=TRUE; return(0); } } int res; LONG timeout; void main() { setup_adc_ports(NO_ANALOGS); setup_adc(ADC_OFF); setup_spi(FALSE); setup_wdt(WDT_OFF); setup_timer_0(RTCC_INTERNAL); setup_timer_1(T1_DISABLED); setup_timer_2(T2_DISABLED,0,1); setup_comparator(NC_NC_NC_NC); setup_vref(FALSE); setup_oscillator(False); lcd_init(); delay_ms(100); lcd_putc("\fvaleur:"); output_low(RS485_ENABLE_PIN); while(1){ output_high(RS485_ENABLE_PIN); putc(0x00); putc(0x25); delay_ms(10); timeout=0; deb: output_low(RS485_ENABLE_PIN); delay_ms(10); res=timed_getc(); lcd_gotoxy(4,2); printf(lcd_putc,"%4U",res); delay_ms(100); } // TODO: USER CODE!! }
-----