malik ahsan
Newbie level 5
- Joined
- Jan 4, 2013
- Messages
- 9
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,360
TXREG = TX_BYTE;
while(!TRMT);
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 #include<htc.h> void uart_init(void); void TX(unsigned char TX_BYTE); unsigned char a; void main() { uart_init(); while(1); } void uart_init(void) { TRISC7 = 1; TRISC6 = 0; SPBRG = 5; // 115200 BRGH = 1; 11.0592 Mhz // SPBRG = 129; // 9600 brgh = 1; 20 Mhz // SPBRG = 64; // 19200 brgh = 1; 20 Mhz TXSTA = 0×24; RCIE =1 ; GIE =1; PEIE =1; RCSTA = 0×90; } void interrupt receive(void) { if(RCIE && RCIF) { RCIF = 0; TX(RCREG); } } void TX(unsigned char TX_BYTE) { TXREG = TX_BYTE; while(!TRMT); }
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 #include <16F877A.h> #device adc=8 #FUSES NOWDT //No Watch Dog Timer #FUSES HS //High speed Osc (> 4mhz) #FUSES NOPUT //No Power Up Timer #FUSES NOPROTECT //Code not protected from reading #FUSES NODEBUG //No Debug mode for ICD(In Circuit Debbuging) #FUSES NOBROWNOUT //No brownout reset #FUSES NOLVP //No low voltage programing, B3(PIC16) or B5(PIC18) used for I/O #FUSES NOCPD //No EE protection #FUSES WRT_50% //Lower half of Program Memory is Write Protected #use delay(clock=16000000) //Frequency 20MHz #use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8) //Declaring USART #define LCD_TYPE 2 //Using 16x2 Alphanumeric LCD #include <lcd.c> float x,y; int a; #int_EXT void EXT_isr(void) { printf("1\n\r"); delay_ms(100); printf("Emergency at 1\n\r"); output_high(pin_B4); output_high(pin_B5); printf(lcd_putc,"\fEmergency at 1\r"); delay_ms(6000); output_low(pin_B4); output_low(pin_B5); } #int_TIMER1 void TIMER1_isr(void) { x=((read_adc()/255.0)*5.00); //Using 8-bit ADC with external reference of 5V printf("%f\n\r",x); //Reading ADC value printf(lcd_putc,"\fVoltage=%f V",x); //Displaying Voltage on LCD y=(x/5)*100; //Calculating Percentage of remaining charge printf(lcd_putc,"\nRemaining=%f",y); //Displaying Remaining voltage delay_ms(12000); } void main() { lcd_init(); setup_adc_ports(AN0_VREF_VREF); setup_adc(ADC_CLOCK_DIV_64); setup_psp(PSP_DISABLED); setup_spi(SPI_SS_DISABLED); setup_timer_0(RTCC_INTERNAL|RTCC_DIV_4); setup_timer_1(T1_INTERNAL|T1_DIV_BY_4); setup_timer_2(T2_DISABLED,0,1); setup_comparator(NC_NC_NC_NC); setup_vref(FALSE); enable_interrupts(INT_EXT); enable_interrupts(INT_TIMER1); enable_interrupts(GLOBAL); ext_int_edge(H_TO_L); clear_interrupt(int_timer1); while(1) { a=getc(); if (a==49) { printf(lcd_putc,"\fEmergency at 1\n\r"); output_high(pin_B5); output_high(pin_B4); delay_ms(1000); output_low(pin_B5); output_low(pin_B4); } if (a==50) { printf(lcd_putc,"\fEmergtency at 2\n\r"); delay_ms(1000); printf("2\n\r"); output_high(pin_B6); output_high(pin_B4); delay_ms(1000); output_low(pin_B6); output_low(pin_B4); } if (a==51) { printf(lcd_putc,"\fEmergtency at 3\n\r"); delay_ms(1000); printf("3\n\r"); output_high(pin_B7); output_high(pin_B4); delay_ms(1000); output_low(pin_B7); output_low(pin_B4); } } }
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 #include <16F877A.h> #device adc=8 #FUSES NOWDT //No Watch Dog Timer #FUSES HS //High speed Osc (> 4mhz) #FUSES NOPUT //No Power Up Timer #FUSES NOPROTECT //Code not protected from reading #FUSES NODEBUG //No Debug mode for ICD(In Circuit Debbuging) #FUSES NOBROWNOUT //No brownout reset #FUSES NOLVP //No low voltage programing, B3(PIC16) or B5(PIC18) used for I/O #FUSES NOCPD //No EE protection #FUSES WRT_50% //Lower half of Program Memory is Write Protected #use delay(clock=16000000) //Frequency 20MHz #use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8) //Declaring USART #define LCD_TYPE 2 //Using 16x2 Alphanumeric LCD #include <lcd.c> float x,y; int a; #int_EXT void EXT_isr(void) { printf("1\n\r"); delay_ms(100); printf("Emergency at 1\n\r"); output_high(pin_B4); output_high(pin_B5); printf(lcd_putc,"\fEmergency at 1\r"); delay_ms(6000); output_low(pin_B4); output_low(pin_B5); } #int_TIMER1 void TIMER1_isr(void) { x=((read_adc()/255.0)*5.00); //Using 8-bit ADC with external reference of 5V printf("%f\n\r",x); //Reading ADC value printf(lcd_putc,"\fVoltage=%f V",x); //Displaying Voltage on LCD y=(x/5)*100; //Calculating Percentage of remaining charge printf(lcd_putc,"\nRemaining=%f",y); //Displaying Remaining voltage delay_ms(12000); } void main() { lcd_init(); setup_adc_ports(AN0_VREF_VREF); setup_adc(ADC_CLOCK_DIV_64); setup_psp(PSP_DISABLED); setup_spi(SPI_SS_DISABLED); setup_timer_0(RTCC_INTERNAL|RTCC_DIV_4); setup_timer_1(T1_INTERNAL|T1_DIV_BY_4); setup_timer_2(T2_DISABLED,0,1); setup_comparator(NC_NC_NC_NC); setup_vref(FALSE); enable_interrupts(INT_EXT); enable_interrupts(INT_TIMER1); enable_interrupts(GLOBAL); ext_int_edge(H_TO_L); clear_interrupt(int_timer1); while(1) { a=getc(); if (a==49) { printf(lcd_putc,"\fEmergency at 1\n\r"); output_high(pin_B5); output_high(pin_B4); delay_ms(1000); output_low(pin_B5); output_low(pin_B4); } if (a==50) { printf(lcd_putc,"\fEmergtency at 2\n\r"); delay_ms(1000); printf("2\n\r"); output_high(pin_B6); output_high(pin_B4); delay_ms(1000); output_low(pin_B6); output_low(pin_B4); } if (a==51) { printf(lcd_putc,"\fEmergtency at 3\n\r"); delay_ms(1000); printf("3\n\r"); output_high(pin_B7); output_high(pin_B4); delay_ms(1000); output_low(pin_B7); output_low(pin_B4); } } }
i am using ccs pic c compiler
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?