/* * File: test2_mod.c * Author: TK * * Created on 2014/10/23, 15:45 * Modify on 2019/12/20 TK Modifiy of Configration bit */ #include #include #include #include "lcd_disp.h" #include "PracticeBox.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 /* 0.6107usx256x64=10ms */ 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 */ { T0IF = 0; /* Timer Interrupt Flag CLS */ sec ++; if( sec == SEC_MAX ) { sec = 0; t_int_flag ++; } } // =============== 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 */ practice_Box_init(); /* Practice BOX initilize */ write_char('A'); disp_number( 5, 2, 1); locate(3, 2); write_str("TEST CODE 2"); locate(0, 3); write_str("Practice BOX sample"); while(1) { /*-------------------------*/ /* Check LED & SW function */ /*-------------------------*/ sw_stat = PORTB; light_LED(~sw_stat); /*----------------------------*/ /* Check SW2 -> move Motor #1 */ /*----------------------------*/ if( (sw_stat& 0x40)==0 ) { move_Box_Motor( 1 /*No.*/, 1 /*ON*/ ); light_Box_LED( 4 /*No.*/, 1 /*ON*/ ); } else { move_Box_Motor( 1 /*No.*/, 0 /*OFF*/ ); light_Box_LED( 4 /*No.*/, 0 /*OFF*/ ); } /*----------------------------*/ /* Check SW3 -> move Motor #2 */ /*----------------------------*/ if( (sw_stat& 0x20)==0 ) { move_Box_Motor( 2 /*No.*/, 1 /*ON*/ ); light_Box_LED( 4 /*No.*/, 1 /*ON*/ ); } else { move_Box_Motor( 2 /*No.*/, 0 /*OFF*/ ); light_Box_LED( 4 /*No.*/, 0 /*OFF*/ ); } /*------------------------------*/ /* Check BOX SW & Light BOX LED */ /*------------------------------*/ if( read_Box_SW( 1 /*No.*/ )==1 ) { light_Box_LED( 1 /*No.*/, 1 /*ON*/ ); } else { light_Box_LED( 1/*No.*/, 0 /*OFF*/ ); } if( read_Box_SW( 2 /*No.*/ )==1 ) { light_Box_LED( 3 /*No.*/, 1 /*ON*/ ); } else { light_Box_LED( 3 /*No.*/, 0 /*OFF*/ ); } /*----------------------------------*/ /* Check BOX Sensor & Light BOX LED */ /*----------------------------------*/ if( read_Box_Sensor( 1 /*No.*/ )==1 ) { light_Box_LED( 1 /*No.*/, 0 /*OFF*/ ); } else { light_Box_LED( 1 /*No.*/, 1 /*ON*/ ); } if( read_Box_Sensor( 2 /*No.*/ )==1 ) { light_Box_LED( 2 /*No.*/, 0 /*OFF*/ ); } else { light_Box_LED( 2 /*No.*/, 1 /*ON*/ ); } } /* while */ return (EXIT_SUCCESS); }