// File Name : main.c // Programmed by Hyun Jee // Program Date : Tue., Jan. 11, 2005 // #include #include "timer.h" //----------- ADC header file ------------// /* LCD Commands*/ #define DISPLAY_ON1 0x0C /* display on, cursor off, blink off */ #define DISPLAY_ON2 0x0D /* display on, cursor off, blink on */ #define DISPLAY_ON3 0x0E /* display on, cursor on, blink off */ #define DISPLAY_ON4 0x0F /* display on, cursor on, blink on */ #define DISPLAY_OFF 0x08 /* display off, cursor off, blink off */ #define CLEAR_DISPLAY 0x01 #define CLEAR_DISPLAY2 0x00 #define RETURN_HOME 0x02 /* to first position on display */ #define ENTRY_MODE1 0X06 /* entry mode: incrmnt +1, not shift */ #define ENTRY_MODE2 0X07 /* entry mode: incrmnt +1, shift */ #define ROTATE_RIGHT 0X14 /* Cursor rotate right */ #define ROTATE_LEFT 0X10 /* Cursor rotate left */ #define FUNCTION_SET1 0X30 /* 8 bit interface, 5x7 dots, 1 lines */ #define FUNCTION_SET2 0X38 /* 8 bit interface, 5x7 dots, 2 lines */ #define DDRAM_ADDR_EVEN 0x80 /* DDRAM Initialize */ #define DDRAM_ADDR_ODD 0xC0 /* DDRAM Initialize */ // Declaration of the Variables xdata unsigned char *pcode; // for External Memory data unsigned char temp1; // for Temporary Data data unsigned char temp; data unsigned char i; // for Loop Parameters data unsigned char p; // for Loop Parameters data unsigned char port_change; // for PORT Display Delection data unsigned char port_value_change; // for PORT Value Update Change data unsigned char port_display_change; // for PORT Display Selection unsigned int loop_cnt; // for Loop Parameter @ timer0 unsigned char display_count; // for Display Parameter @timer0 unsigned char received_data; // for received data from UART RX pin (RX : Receive Side) // Prototype Functions // 1. System Initialization void initialize(void); // 2. Led Output //void output_led(void); // Sub Function : 8. void msec(int) { /* delay function for m seconds */ void msec(int Delay) { int i, j; for(j=0; j TH0 = 0x78; // TH0 for Auto-reload // (Fosc/11.0592MHz)^-1*(256-TH0) = Timing Duty // When Fosc = 11.0592MHz and TH0 = 0x78, // Timing Duty is 0.125msec (124.7 usec) TF0 = 0; ET0 = 1; // Timer 0 Interrupt Enable //---------------------------------------------------- SM0 = 0; // SM0,SM1 = [0,1] : UART Mode 1 (8-bit UART) SM1 = 1; //CKCON |= 0x10; // T1M = 1; TH1 = 0xFD; // Refer to the UART table at Brief Manual of MiDAS1.0 Family. REN = 1; // Reception Enable TF1 = 0; PS = 1; // UART Priority Enable ES = 1; // UART Interrupt (Commnucation) Enable //---------------------------------------------------- EA = 1; // All Interrupts Enable //---------------------------------------------------- // The Initialization of Variables pcode = (unsigned char xdata *)0x0000; display_count = 0; loop_cnt = 0; } // End: void initialize(void) // Sub Function : Timer 0 Interrupt void timer0_int(void) interrupt TF0_VECTOR { // 7-segment Display if (loop_cnt == 4000) { // 2000 : 0.25sec, 4000 : 0.50sec (Time Duty : 0.125msec) loop_cnt = 0; switch (display_count) { case 0 : pcode = (unsigned char xdata *) 0xF600; // Port B (7-segment Display) *(pcode) = D0; // Refer to timer.h file about MACRO "D0". display_count++; break; case 1 : pcode = (unsigned char xdata *) 0xF600; // Port B (7-segment Display) *(pcode) = D1; // Refer to timer.h file about MACRO "D0". display_count++; break; case 2 : pcode = (unsigned char xdata *) 0xF600; // Port B (7-segment Display) *(pcode) = D2; // Refer to timer.h file about MACRO "D0". display_count++; break; case 3 : pcode = (unsigned char xdata *) 0xF600; // Port B (7-segment Display) *(pcode) = D3; // Refer to timer.h file about MACRO "D0". display_count++; break; case 4 : pcode = (unsigned char xdata *) 0xF600; // Port B (7-segment Display) *(pcode) = D4; // Refer to timer.h file about MACRO "D0". display_count++; break; case 5 : pcode = (unsigned char xdata *) 0xF600; // Port B (7-segment Display) *(pcode) = D5; // Refer to timer.h file about MACRO "D0". display_count++; break; case 6 : pcode = (unsigned char xdata *) 0xF600; // Port B (7-segment Display) *(pcode) = D6; // Refer to timer.h file about MACRO "D0". display_count++; break; case 7 : pcode = (unsigned char xdata *) 0xF600; // Port B (7-segment Display) *(pcode) = D7; // Refer to timer.h file about MACRO "D0". display_count++; break; case 8 : pcode = (unsigned char xdata *) 0xF600; // Port B (7-segment Display) *(pcode) = D8; // Refer to timer.h file about MACRO "D0". display_count++; break; case 9 : pcode = (unsigned char xdata *) 0xF600; // Port B (7-segment Display) *(pcode) = D9; // Refer to timer.h file about MACRO "D0". display_count = 0; break; } } loop_cnt++; TF0 = 0; // Timer 0 Overflow Falg Clear } // Sub Function : UART Interrupt (Serial Communication) void uart_int(void) interrupt SIO_VECTOR { while (1) { if (TI) { // Transmit Mode TI = 0; break; } else if (RI) { // Receive Mode received_data = SBUF; SBUF = received_data; // Resend to Serial Port PutChar(received_data); if(received_data == 0x03) // ctrl+c input clearscreen_lcd(); RI = 0; break; } } }