/*
This file contains some routines for the hardware rs232 interface and other small routines.
Here's a lot of assembler-code, although you could do it all in C.
Using C, it's difficult to reach small code sizes...
*/
//==========================================================================================
/*
function to convert two ascii-codes to one real byte
e.g.: 'A' '5' => 165
this is one of the more difficult conversion functions for the compiler,
maybe i'll write this one in assembler soon...
*/
char hex2char(char ander, char einer)
{
if (einer < 60)
einer = einer - 48;
else
einer = einer - 55;
if (ander < 60)
ander = ander - 48;
else
ander = ander - 55;
return ((ander * 16) + einer);
}
//===========================================================================================
//assembler macro for putchr()
asm
{
putchr macro data
movlw data
call _putchr
endm
}
//===========================================================================================
/*
this function is the equivalent to the original putchar(), just for the
hardware rs232 implementation
*/
void putchr(char chr)
{
asm bank _txreg
putchr_loop:
asm
{
btfss PIR1, TXIF
goto _putchr_loop
movwf _txreg
return
}
}
char getchr() //same as above: getchar()
{
asm bank _pir1
getchr_loop:
asm
{
btfss _pir1, RCIF
goto _getchr_loop
bcf _pir1, RCIF
}
return rcreg;
}
void put_CR_LF() //sends a LineFeed and
{ // CarriageReturn
asm putchr 0x0A
asm putchr 0x0D
}
//============================================================================================
//function to show the menu text
void put_menu_txt()
{
asm
{
putchr 'B'
putchr 'o'
putchr 'o'
putchr 't'
putchr 'l'
putchr 'o'
putchr 'a'
putchr 'd'
putchr 'e'
putchr 'r'
}
put_CR_LF();
asm
{
putchr '1'
putchr ' '
putchr 'l'
putchr 'o'
putchr 'a'
putchr 'd'
}
put_CR_LF();
asm
{
putchr '2'
putchr ' '
putchr 's'
putchr 't'
putchr 'a'
putchr 'r'
putchr 't'
}
put_CR_LF();
asm putchr '>'
}
//=======================================================================================
Copyright © 2002-2006 SourceBoost Technologies