#include // Include header file for MCU #include // Include - TopicsExpress



          

#include // Include header file for MCU #include // Include Library for LCD display #define _XTAL_FREQ 8000000 // Define Frequency 20.0 MHz for function __delay_ms __CONFIG(HS & WDTDIS & LVPDIS); // Config. High speed clock,Disable watchdog and Disable LVP unsigned char x; unsigned char s1; unsigned char s2; unsigned char s3; unsigned char sum_code; void Delay_ms(unsigned int tick) { while(tick--) // Loop counter delay time { __delay_ms(1); // Delay 1 ms } } void usart_init() { // Set buadrate 9600 bps SYNC = 0; BRGH = 1; BRG16 = 1; SPBRG = 0x08; SPBRGH = 0x02; TXEN = 1; // Enable transmition CREN = 1; // Enable receive SPEN = 1; // Enable USART transmition/receive } void usart_putc(unsigned char c) { while(!TRMT); // Wait transmition ready TXREG = c; // Send byte } //--------------void void Reads_DTMF() { if(RB6==0&&RB5==0&&RB4==0&&RB3==1) { x=1; } else if(RB6==0&&RB5==0&&RB4==1&&RB3==0) { x=2; } else if(RB6==0&&RB5==0&&RB4==1&&RB3==1) { x=3; } else if(RB6==0&&RB5==1&&RB4==0&&RB3==0) { x=4; } else if(RB6==0&&RB5==1&&RB4==0&&RB3==1) { x=5; } else if(RB6==0&&RB5==1&&RB4==1&&RB3==0) { x=6; } else if(RB6==0&&RB5==1&&RB4==1&&RB3==1) { x=7; } else if(RB6==1&&RB5==0&&RB4==0&&RB3==0) { x=8; } else if(RB6==1&&RB5==0&&RB4==0&&RB3==1) { x=9; } else if(RB6==1&&RB5==0&&RB4==1&&RB3==0) { x=0; } } //------------------ void main() { usart_init(); // Initial USART baudrate 9600 bps TRISB3 = 1; // RB3 set Q1 TRISB4 = 1; // RB4 set Q2 TRISB5 = 1; // RB5 set Q3 TRISB6 = 1; // RB6 set Q4 TRISB7 = 1; // RB7 set STD TRISC1 = 1; // RC1 set sw RESET_ALARM TRISC2 = 1; // RC2 set sw RESET_LED TRISC3 = 1; // RC3 set sw TEST_LED TRISE0 = 1; // RE0 set JINGLE TRISB1 = 1; // RB1 set CHECK_LINE_CONTAC TRISC4 = 1; // RC4 set AC_CHECK TRISC5 = 0; // RC5 DIR Set TRISE1 = 0; // RE1 ALARM TRISC0 = 0; // RC0 HOOK_SW TRISA5 = 0; // RA5 Set LED SESTEM lcd_init(); // Initial LCD lcd_puts(0x80," TEST BY SUPARP"); // Display message lcd_puts(0xC0," TEST 01 "); // Display message while(1) // Infinite loop { RA5=1; Delay_ms(300); RA5=0; Delay_ms(300); if(RC3==0) //TEST_LED { lcd_puts(0x80,"MODE : TEST LED"); // Display message lcd_puts(0xC0,"OUT : SW RESET"); // Display message RC5=1; //open bus line 485 usart_putc(513); //send code 513 Delay_ms(3); RC5=0; } if(RC2==0) //RESET_LED { lcd_puts(0x80," YOU PUSH "); // Display message lcd_puts(0xC0," SW:REST LED "); // Display message RC5=1; //open bus line 485 usart_putc(514); //send code 514 Delay_ms(1000); lcd_puts(0x80,"TEST BY SUPARP "); // Display message lcd_puts(0xC0,"PLEASE PUSH: SW"); // Display message RC5=0; } if(RC1==0) //RESET_ALARM { lcd_puts(0x80," YOU PUSH "); // Display message lcd_puts(0xC0," SW:REST ALARM "); // Display message Delay_ms(1000); lcd_puts(0x80,"TEST BY SUPARP "); // Display message lcd_puts(0xC0,"PLEASE PUSH: SW"); // Display message RE1=1; // ALARM off } if(RB1==1) ///dis 0 { lcd_puts(0x80,"SYSTEM STATUS "); // Display message lcd_puts(0xC0,":DISCONNECT "); // Display message } if(RE0==1) //TEL 0 { lcd_puts(0x80,"SYSTEM STATUS "); // Display message lcd_puts(0xC0,"JINGLE "); // Display message RC0=1; //HOOK on while(RB7==0); Reads_DTMF(); s1=x*100; while(RB7==0); Reads_DTMF(); s2=x*10; while(RB7==0); Reads_DTMF(); s3=x; sum_code=s1+s2+s3; RC5=1; //open bus line 485 usart_putc(sum_code); //send code Delay_ms(3); RC5=0; RC0=0; //HOOK off RE1=0; // ALARM on } } }
Posted on: Sun, 14 Jul 2013 08:54:36 +0000

Trending Topics



Recently Viewed Topics




© 2015