File "serial.c"
Full Path: /home/analogde/www/private/Projet/Example/HC11/serial.c
File size: 1.99 KB
MIME-type: text/x-c
Charset: utf-8
/*============================================================================
Motorola 68HC11
This is a simple program to show serial port and timer polling..
Author: Dusty Nidey, Axiom Mfg.
Date: 11\22\1996
Tools: ImageCraft C Compiler V3.5
==============================================================================*/
#include <hc11.h>
// Constants, not used in this example
const unsigned char SSTRING[] = "Simple String Data";
const unsigned char ANDMASK[] = {0xFB,0xF7,0xEF,0xDF};
// Function Prototypes
char FlashOnOff; // 1 = flash on time, 0 = flash off time
char Ibuf[18]; // serial input buffer
char count;
char count4;
char Rcount;
char Ibyte;
// this function only used for debugging in buffalo monitor
// it is handy to set a breakpoint here, and just call this in your program,
// this way the breakpoint always stays the same
void break_here(){
count=count;
}
// Toggle flashing pins for example
Handle_Timer(){
FlashOnOff ^= 0x01; // toggle flash state, example
}
// After executing STARTUP code on reset, execution begins here
main(){
TFLG2 |= 0x80; // clear timer overflow flag
DDRD |= 0x3C; // set PD2-PD5 to output
// setup serial port
BAUD = 0x30; // 9600 baud, N,8,1
SCCR1 = 0;
SCCR2 = 0x0C;
Rcount=0;
// main loop .. endless
for( ; ;){
if(SCSR & 0x20){ // if incomming serial data
Ibyte = SCDR; // get input byte
Ibuf[Rcount] = Ibyte; // save it
if(Rcount > 18){ // if overflow
Rcount=0; // reset count, ignore this string
}
else ++Rcount; // else, incriment serial count
SCDR = '.'; // example of sending something to serial port
SCDR = Ibyte;
/* NOTE: you can also use the puts and putchar commands as follows
puts("hello"); // send string
putchar(0x0D); // send CR
*/
}
if(TFLG2 & 0x80){ // if timer overflow
TFLG2 |= 0x80; // clear timer overflow flag
if(++count4 > 31){ // if time to flash
count4=0;
Handle_Timer(); // flash output pins in flash mode
}
}
}
}