/********************************************************************
Filename: test232.c
Created: Sunday, October 12, 2003
Author(s): Jonathan Bisson
History:
Purpose: Test file for serialCom.c
Empty RX buffer on timer0 interrupt and echo
the caracters received
Copyrights(c) 2003
*********************************************************************/
#include <system.h>
#include "test232.h"
#include "serialCom.h"
#pragma CLOCK_FREQ 20000000
asm {
list p=16F877
__config H'3F72' ;UNPROTECT&HS&WDTDIS&PWRTEN&BORDIS&LVPDIS&DUNPROT&WRTEN&DEBUGDIS
}
short i16_Timer0Counter;
char i8_Tasks[TASKS_LIMIT];
char i8_TasksCounter;
void on_init( void )
{
i8_TasksCounter = 0;
//All used pins as ouput
porta = 0x00;
trisa = 0x00;
portb = 0xFF;
trisb = 0x00;
portc = 0x00;
trisc = 0x80;
portd = 0x00;
trisd = 0x00;
porte = 0x00;
trise = 0x00;
//Timer0
option_reg = 0xD7; //Internal, prescalar = 1:256
tmr0 = 0;
set_bit( intcon, T0IE );
//SerialPort init
serialInit();
enable_interrupt( PEIE );
enable_interrupt( GIE );
}
void on_timer0( void )
{
if (getRxByteCount() > 0)
{
sendHex(getRxByteCount());
sendString(" byte(s): ");
while(getRxByteCount() > 0)
{
putChar(getChar());
}
sendString("\r\n");
}
}
void on_idle( void )
{
}
void interrupt( void )
{
if ( intcon&0x20 && intcon&0x04 )
{
tmr0 = 0;
clear_bit( intcon, T0IF );
if ( ++i16_Timer0Counter >= 77 )
{
i16_Timer0Counter = 0;
if ( i8_TasksCounter < TASKS_LIMIT )
i8_Tasks[i8_TasksCounter++] = TASK_TIMER0;
}
}
//serialPort interrupt functions
interruptTx();
interruptRx();
}
main()
{
char tmr01;
char tmr02;
on_init();
tmr01 = tmr0;
sendHex(0xff);
tmr02 = tmr0;
sendString("\n\r");
sendHex(tmr02-tmr01);
sendString("\n\r");
sendString("\n\rInit done\n\r");
while (getTxByteCount() != 0); //Wait to be sure that the String is send without
//buffer overwrite (blocking)
sendString("This string is to long so many caracters will be overwrite in the circular buffer\n\r");
for (;;)
{
while ( i8_TasksCounter )
{
switch( i8_Tasks[--i8_TasksCounter] )
{
case TASK_TIMER0:
on_timer0();
break;
}
}
on_idle();
}
}
Copyright © 2002-2006 SourceBoost Technologies