/* * File: test1.c * Author: * * Created on 2012/08/08, 19:38 * Modify Comment [Timer0] 2012/08/08 TK * Modify on 2019/12/20 TK Modifiy of Configration bit */ #include #include #include #include "lcd_disp.h" #include "sensor.h" /* CONFIGRATION */ //__CONFIG(FOSC_INTRC_NOCLKOUT & WDTE_OFF & PWRTE_OFF & MCLRE_ON & CP_OFF & CPD_OFF & BOREN_OFF & IESO_OFF & FCMEN_OFF & LVP_OFF); //__CONFIG(WRT_OFF & BOR4V_BOR40V); /* CONFIG 1 */ #pragma config FOSC = INTRC_NOCLKOUT #pragma config WDTE = OFF #pragma config PWRTE = OFF #pragma config MCLRE = ON #pragma config CP = OFF #pragma config CPD = OFF #pragma config BOREN = OFF #pragma config IESO = OFF #pragma config FCMEN = OFF #pragma config LVP = OFF /* CONFIG 2 */ #pragma config WRT = OFF #pragma config BOR4V = BOR40V /* Grobal for Timer */ #define SEC_MAX 32 /* 40ms X 32 = 1.28sec */ int sec=0; int t_int_flag=0; /*---------------------*/ /* Intraupt Subroutine */ /*---------------------*/ //#pragma INTERRUPT rtcc_isr static void __interrupt () rtcc_isr( void ) /* for Online */ // static void interrupt rtcc_isr( void ) /* for Standalone */ { /*------------------------------------*/ /* case of Timer0 interrupt */ /* Timer0 -> (1/6553675MHz)*4*256*256 */ /* Prescaler : 256 */ /* TMR0 : 8bit reg -> 256 */ /* Intruppt is genarated every 40ms */ /*------------------------------------*/ if( T0IF == 1 ) { T0IF = 0; /* Timer Interrupt Flag CLS */ sec ++; if( sec == SEC_MAX ) { sec = 0; t_int_flag ++; /* Flag is genarated every 1.28sec */ } } /* case of Port B */ else if( RBIF == 1 ) { /* Plase write Port B Interrrupt process */ } } // =============== PIC 16F887 ====================== static void pic_init() { // OSCCON = 0x70; // INTOSC 8MHz PSTRCON = 0x00; // assigned to port pin /* Set Port B*/ ANSELH = 0x00; // AN Disable (RB5-RB0) WPUB = 0x00; // Pull-up disable INTCON = 0x00; // Intrauppt disable IOCB = 0x00; // Intrauppt charge disable CCP1CON = 0x00; CM2CON1 = 0x02; OPTION_REG = 0xFF; // Pull-up disable TRISB = 0xFF; // IN // PORTB = 0x11; // High /* Set Port C */ RCSTA = 0x00; // Serial disable (RC7-6) SSPCON = 0x00; // Serial disable (RC5-4) TRISC = 0x00; // OUT PORTC = 0x00; // Low /* Set Port D config */ TRISD = 0xC0; // bit 0-5 OUT, bit6-7 IN } void light_LED( char data ) { PORTD = (data>>1) & 0x3F; } int main(int argc, char** argv) { char sw_stat; char rot_dir; int rot_number = 0; short temp_dat, temp_dat2; short old_temp_dat; short temp_check_count = 0; char t_char_flag = 0; pic_init(); /* PIC kit board initilize */ init_lcd(); /* LCD unit initilize */ sensor_init(); /* Rorary Encoder/Temputer sensor initilize */ timer0_init(); /* Timer0 Initilize */ write_char('E'); disp_number( 5, 2, 1); locate(3, 2); write_str("TEST CODE"); locate(3, 3); write_str("Hello world!"); /* Timer0 Interrupt */ T0IE = 1; /* Enable Interrupt */ GIE = 1; /* Enable Grobal Interrupt */ while(1) { /*-------------------------*/ /* Check LED & SW function */ /*-------------------------*/ sw_stat = PORTB; light_LED(~sw_stat); /*--------------*/ /* Rotary Check */ /*--------------*/ rot_dir = check_Rotary(); switch( rot_dir ) { case CW: rot_number ++; if( rot_number > 9 ) { rot_number = 0; } disp_number( rot_number, 8, 1); break; case CCW: rot_number --; if( rot_number < 0 ) { rot_number = 9; } disp_number( rot_number, 8, 1); break; default: break; } /*------------------------*/ /* Check Temputure Sensor */ /*------------------------*/ if( temp_check_count == 30000 ) { locate(13, 1); write_char('*'); temp_dat = check_Tempture()%100; disp_number( (int)(temp_dat/10), 11, 1); disp_number( (int)(temp_dat%10), 12, 1); temp_check_count = 0; locate(13, 1); write_char(' '); } /* if */ else { temp_check_count ++; } /*------------------------*/ /* Timer0 & INT Check */ /*------------------------*/ if( t_int_flag ) { locate(19, 1); if( t_char_flag ) { write_char(' '); t_char_flag = 0; } else { write_char('I'); t_char_flag ++; } t_int_flag = 0; } } /* while */ return (EXIT_SUCCESS); }