Main Page   Data Structures   File List   Data Fields   Globals  

uartsw.c

Go to the documentation of this file.
00001 /*! \file uartsw.c \brief Software Interrupt-driven UART function library. */
00002 //*****************************************************************************
00003 //
00004 // File Name    : 'uartsw.c'
00005 // Title        : Software Interrupt-driven UART function library
00006 // Author       : Pascal Stang - Copyright (C) 2002
00007 // Created      : 7/20/2002
00008 // Revised      : 8/04/2002
00009 // Version      : 0.1
00010 // Target MCU   : Atmel AVR Series
00011 // Editor Tabs  : 4
00012 //
00013 // This code is distributed under the GNU Public License
00014 //      which can be found at http://www.gnu.org/licenses/gpl.txt
00015 //
00016 //*****************************************************************************
00017 
00018 #ifndef WIN32
00019     #include <avr/io.h>
00020 #endif
00021 
00022 #include "global.h"
00023 #include "uartsw.h"
00024 
00025 // Program ROM constants
00026 
00027 // Global variables
00028 
00029 // functions
00030 
00031 // initializes software UART system
00032 void uartswInit(void)
00033 {
00034     // disble the timer1 output compare B interrupt
00035     cbi(TIMSK, OCIE1B);
00036     // set the prescaler for timer1
00037     timer1SetPrescaler(TIMER_CLK_DIV256);
00038     // attach the software uart service routine to timer1 output compare B
00039     timerAttach(TIMER1OUTCOMPAREB_INT, swuartService);
00040     // set initial interrupt time
00041     u16 OCValue;
00042     // read in current value of output compare register OCR1A
00043     OCValue =  inb(OCR1AL);     // read low byte of OCR1A
00044     OCValue += inb(OCR1AH)<<8;  // read high byte of OCR1A
00045     // increment OCR1A value by nextTics
00046     OCValue += 1000; 
00047     // set future output compare time to this new value
00048     outb(OCR1AH, (OCValue>>8));         // write high byte
00049     outb(OCR1AL, (OCValue & 0x00FF));   // write low byte
00050     // enable the timer1 output compare B interrupt
00051     sbi(TIMSK, OCIE1B);
00052 }
00053 
00054 // turns off software UART system
00055 void uartswOff(void)
00056 {
00057     // disable the timer1 output compare A interrupt
00058     cbi(TIMSK, OCIE1B);
00059     // detach the service routine
00060     timerDetach(TIMER1OUTCOMPAREB_INT);
00061 }
00062 
00063 
00064 void uartswService(void)
00065 {
00066 
00067 }

Generated on Tue Feb 4 20:18:37 2003 for Procyon AVRlib by doxygen1.3-rc2