/*************************************************************************** test.c - description ------------------- begin : Sun Sep 3 2000 copyright : (C) 2000 by William Rachelson email : gurufool@cc.gatech.edu ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "ezusb.h" // --------------------------------------------------------------------------- // Defines. // --------------------------------------------------------------------------- #define FALSE 0 #define TRUE 1 #define LOW 0 #define HIGH 1 // --------------------------------------------------------------------------- // Function prototypes. // --------------------------------------------------------------------------- void init_ser( void ); void ser_printString(char *); void ser_putc(unsigned char); // --------------------------------------------------------------------------- // Global variable definitions. // --------------------------------------------------------------------------- unsigned char xdata ser_txIndexIn; unsigned char xdata ser_txIndexOut; unsigned char xdata ser_txBuffer[0x100]; unsigned char xdata ser_rxBuffer[0x100]; static bit ser_txBusy; //------------------------------------------------------------------ // Main routine here //------------------------------------------------------------------ void main( void ) { init_ser(); // Initialize serial ops. ser_printString("HELLO WORLD"); } // --------------------------------------------------------------------------- // Initialize serial operations. // --------------------------------------------------------------------------- void init_ser( void ) { //Disable Serial Ints ES0 = FALSE; //Initialize local vars ser_txBusy = 0; ser_txIndexIn = 0; ser_txIndexOut = 0; /* Setup baud and port */ // PORTBCFG |= 0xC; //PORTBCFG RxD1 and TxD1 HIGH // SCON1 = 0x50; // Mode 1 PORTCCFG |= 3; SM0 = 0; SM1 = 1; // Mode 1 SM2 = 1; // RI on valid STOP only REN = 1; // Receive Enabled // Timer 2 setup TCLK = 1; // Use the Timer 2 for the Tx clk RCLK = 1; // Use the Timer 2 for the Rx clk C_T2 = 0; // Use it as a timer, not counter TH2 = 0xFF; // Set the counter to reload soon TL2 = 0xFF; //RCAP2H = 0xFF; // 19.2kHz //RCAP2L = 0xD9; RCAP2H = 0xFF; RCAP2L = 0xB2; // 9.6kHz TR2 = 1; // Start the Timer 2 running TI = 0; // Clear the transmit flag // SMOD1 = 1; //Double Baud rate // TMOD = 0x20; // Timer 1, mode 2, 8-bit reload. // T1M = 1; //Use Clock 24/4 // TH1 = 0xD9; // 9600 baud // TR1 = 1; // Timer 1 run. // PS1 = TRUE; // High priority. ES0 = TRUE; // Enable serial interrupt. //Enable Interrupts EA = 1; } void ser_interrupt_handler(void) interrupt 4 using 1 //change me for uart1/0! { ES0 = 0; if (TI) { TI = 0; if (ser_txIndexIn == ser_txIndexOut) { ser_txBusy = 0; } else { SBUF0 = ser_txBuffer[ser_txIndexOut++]; } } //clear recv ints and ignore them if (RI) { RI = 0; } ES0 = 1; } void ser_putc(unsigned char c) { ES0 = 0; if (ser_txBusy) { ser_txBuffer[ser_txIndexIn++] = c; } else { ser_txBusy = 1; SBUF0 = c; } ES0 = 1; } void ser_printString(char *String) { while (*String) { ser_putc(*String++); } }