#ifndef _int_c_ #define _int_c_ #include "int.h" #pragma SRC volatile int idata YEAR; volatile int idata MONTH; volatile int idata DAY; volatile int idata HOUR; volatile int idata MINUTE; volatile int idata SECOND; volatile int idata MSECOND; volatile int idata TIMER10; volatile int idata THISMDAYS; void init_serial(unsigned int baud) { TxD = 1; DTxD = 1; DRxD = 0; S0RIC = 0x0a; S0TIC = 0x0b; serinbufct = 0; serinflag = 0; seroutbufct = 0; seroutflag = 0; S0BG = baud; S0CON = 0x8011; } void deinit_serial( void ) { S0RIC = 0x0a; S0TIC = 0x0b; S0CON = 0; serinflag = 0; seroutflag = 0; } void serial_receive( int wait ) { while( serinflag == 1 ) { ; } serinbufct = 0; serinflag = 1; S0RIC = 0x4a; if( wait ){ while( serinflag < 2 ){ ; } } } void serial_transmit( int wait ) { while( seroutflag == 1 ) { ; } seroutbufct = 0; seroutflag = 1; S0TIC = 0x4b; S0TBUF = seroutbuf[0]; if( wait ){ while( seroutflag < 2 ){ ; } } } unsigned char serinbuf[ SERIALMAXLENGTH + 2 ]; unsigned int serinbufct; unsigned int serinflag; void ser_receive_int (void) interrupt SERIAL_RECEIVE_INT = 0x2B using bankSORIC { serinbuf[serinbufct] = S0RBUF; if( ( serinbuf[serinbufct] < 0x20 ) || ( serinbufct >= SERIALMAXLENGTH ) ){ S0RIC = 0x0a; serinbuf[serinbufct] = 0; serinbufct++; serinflag = 2; } else { serinbufct++; serinflag = 1; } } unsigned char seroutbuf[ SERIALMAXLENGTH + 2 ]; unsigned int seroutbufct; unsigned int seroutflag; void ser_transmit_int (void) interrupt SERIAL_TRANSMIT_INT = 0x2A using bankSOTIC { if( ( seroutbuf[seroutbufct] < 0x20 ) || ( seroutbufct >= SERIALMAXLENGTH ) ){ S0TIC = 0x0b; seroutflag = 2; } else { seroutbufct++; seroutflag = 1; S0TBUF = seroutbuf[seroutbufct]; } } void initTimerInt( void ) { T3IC = TIMERINTOFF; T3CON = TIMERSTOP; T4CON = TIMERSET; T4 = TIMERRELOAD; T3 = TIMERRELOAD; } void startTimerInt( void ) { TIMER10 = 0; T3 = TIMERRELOAD; T4 = TIMERRELOAD; T3CON = TIMERSTART; T3IC = TIMERINTON; } void stopTimerInt( void ) { T3IC = TIMERINTOFF; T3CON = TIMERSTOP; } #pragma ASM ;P2 DEFR 0FFC0H P7 DEFR 0FFD0H P8 DEFR 0FFD4H #pragma ENDASM //interrupt every 1/10000 second void timer_int (void) interrupt TIMER_INT = 0x23 using TIMER_BANK { TIMER10++; if( TIMER10 >= 10 ){ TIMER10 = 0; MSECOND++; if( MSECOND >= 1000 ){ MSECOND = 0; SECOND++; if( SECOND >= 60 ){ SECOND = 0; MINUTE++; if( MINUTE >= 60 ){ MINUTE = 0; HOUR++; if( HOUR >= 24 ){ HOUR = 0; DAY++; if( DAY > THISMDAYS ) { DAY = 1; MONTH++; if( MONTH > 12 ){ MONTH = 1; YEAR++; } } } } } } } /// so updating of date/time is down /// here we do the other work /// /// } #endif