home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
listings
/
v_09_03
/
9n03039d
< prev
next >
Wrap
Text File
|
1991-01-22
|
3KB
|
132 lines
/*************************************************************
* NAME : Interupt.c
* DESCRIPTION : Interrupt routines for the preset controller
*************************************************************/
/**************************************************************
*
* NAME : rcv_msg
* DESCRIPTION: called by the interrupt routine which is
* invoked by uart interrupt bit.
* COMPATIBLE LANGUAGES: <Assembler only>
**************************************************************/
#include "serial.h"
#include "que.h"
extern TRCSR;
extern TDR;
extern xstatus;
extern struct g_queue xmit_que;
extern struct g_queue in_que;
extern RDR;
rcv_msg()
{
unsigned char xstatus, temp;
unsigned int remove, insert;
xstatus = TRCSR;
if (xstatus & RDRF) /* did we receive something? */
{
temp = RDR;
remove = in_que.remove;
insert = in_que.insert;
if ((insert+1!=remove) && (insert-remove!=kqlength-1))
{ /* queue is full */
in_que.que[insert++] = temp;
if (insert == kqlength)
insert = 0;
in_que.insert = insert;
in_que.empty = false;
}
}
if (xstatus & TDRE)
{ /* do we have something to send? */
if(xmit_que.empty == false)
{
remove = xmit_que.remove;
TDR = xmit_que.que[remove++];
if (remove == kqlength)
remove = 0;
xmit_que.remove = remove;
if (remove == xmit_que.insert)
xmit_que.empty = true;
}
else
{
/* turn off the interupt for transmit buffer empty and
turn off the serial transmit buffer */
TRCSR &= ~TIE;
}
}
}
/**************************************************************
*
* NAME : counter_irq
*
* DESCRIPTION: called by the interrupt routine which is
* invoked by global timer interrupt - increments
* the global value of time and reads the keyboard.
********************************************************************/
extern enable_timer;
extern globaltime;
extern flashtime;
extern dspy;
extern disable_on;
extern keyboard_port;
extern P1DR;
extern pad_read;
counter_irq()
{
unsigned char i,line;
static unsigned char keyport;
unsigned int temp;
/* clear the TOF bit in the timer control & status reg.
* AND then clear the interupt mask in the condition code reg.
*/
;
#asm
XREF TCSR?
LDD TCSR?
CLI
#endasm
/* increment the global timer variable */
if (enable_timer) globaltime += 1;
/* increment the flash time */
flashtime += 1;
/* refresh the display */
show(dspy);
/* if (!disable_on) then read the keypad */
if (!disable_on)
{
line = 0x8;
for (i=0; i<4; i++)
{
P1DR = line;
line >>= 1;
keyport = P1DR;
if (keyport & 0xf0)
break;
}
if (i==0)
keyboard_port = (keyport & 0xf0) | 1;
else if (i==1)
keyboard_port = (keyport & 0xf0) | 2;
else if (i==2)
keyboard_port = (keyport & 0xf0) | 4;
else if (i==3)
keyboard_port = (keyport & 0xf0) | 8;
pad_read = true;
}
}