Академический Документы
Профессиональный Документы
Культура Документы
//-- ms Delay
//-- us Delay between addressing and reading
\0";
DelayUs(100);
PTBD = 0x2;
DelayUs(40);
lcd_write(0x28);
lcd_write(0x08);
lcd_write(0x0F);
lcd_write(0x06);
}
for(;;) {
__RESET_WATCHDOG(); /* feeds the dog */
PTDD = 0x00;
DelayMs(6);
PTED = 0x4F; /*O */
PTDD = 0x03;
DelayUs(40);
PTED = 0x6D; /*M*/
PTDD = 0x00;
DelayMs(6);
PTED = 0x61; /*A*/
PTDD = 0x03;
DelayUs(40);
PTED = 0x72; /*R*/
PTDD = 0x03;
DelayMs(6);
PTED = 0x20; /*SPACE*/
PTDD = 0x00;
DelayUs(40);
PTED = 0x4D; /*M*/
PTDD = 0x03;
DelayMs(6);
PTED = 0x61; /*A*/
PTDD = 0x03;
DelayUs(40);
PTED = 0x72; /*R*/
PTDD = 0x03;
DelayMs(6);
PTED = 0x74; /*T*/
PTDD = 0x03;
DelayUs(40);
PTED = 0x69; /*I*/
PTDD = 0x03;
DelayMs(6);
PTED = 0x6E; /*N*/
PTDD = 0x03;
DelayUs(40);
PTED = 0x65; /*E*/
PTDD = 0x03;
DelayMs(6);
PTED = 0x7A; /*Z*/
PTDD = 0x03;
}/* loop forever */
/* please make sure that you never leave main */
//-- Setup Variables -NewData=0;
Head=0;
BeepNow=0;
GotoCommand=0;
GotoNew=0;
GotoData=21;
//-- Set up Ports -PTGD_PTGD5=0;
PTED_PTED5=0;
PTHD_PTHD3=0;
//-- Set Chip Sel Pin High to indicate Busy to the master
ChipSel=1;
TChipSel=0;
//-- Set Up Interrupts -TPM1CH2=0;
//-- Enable the IRQ Mode
PTCE4 = 0xFF;
//-- IRQ configured as input
PTCE4 = 0x07;
//-- IRQ Controls as input
PTCE4 = 0x00;
//-- NULL Output to start with
//-- Initialize the LCD -lcd_init();
lcd_clear();
// ScrollMessage(0,"
// ScrollMessage(1,"
");
}
KeyPressed=KeyRead();
if(KeyPressed != 0)
{
KeyPressed=DecodeKey(KeyPressed);
if(KeyPressed != LastKeyPressed)
{
LastKeyPressed=KeyPressed;
PTBD= KeyPressed;
}
}
}
}
void DelayMs(unsigned char cnt){
while (cnt < 150000){
cnt = cnt + 1 ;
}
}
void DelayUs(unsigned char _cnt){
while(_cnt < 3000000){
_cnt = (_cnt + 1);
}
}
void lcd_write(unsigned char c){
PTBD = c >> 4;
PTBD = c;
DelayUs(40);
}
void lcd_puts(const char *s){
LCD_RS = 1;
// write characters
while(*s){
lcd_write(*s++);
}
}
//**********************************************************************
//GlobalInterrupt - exactly what it says!!
//**********************************************************************
void interrupt GlobalInterrupt(void)
{
char Icount,TempD;
if(IRQSC)
{
if(IBF)
// Input Buffer Full
{
TempD=PTBD;
switch(TempD)
{
default:
if(GotoCommand==1)
{
GotoData=TempD;
GotoCommand=0;
GotoNew=1;
break;
}
if(PutchCommand==1)
{
PutchData=TempD;
PutchNew=1;
PutchCommand=0;
break;
}
Buffer[Head++]=TempD;
//-- Add Data to the Buffer and point to next
if(Head < 40) break;
//-- If not off the end then exit ...
Head=20;
//-- ... else CR!
break;
//**************************************
case LCD_CRLF:
//-- Combination of CR and LF
if(Head < 20)
{
Head=0;
}
else
{
Head=20;
}
//**************************************
case LCD_LF:
//-- Line Feed
if(Head >=20)
{
for(Icount=0;Icount<20;Icount++)
{
Buffer[Icount]=Buffer[Icount+20];
Buffer[Icount+20]=0; //-- Clear the data out
}
}
else
{
Head+=20;
}
break;
//**************************************
case LCD_CR:
//-- Carrage Return
if(Head < 20)
{
Head=0;
}
else
{
Head=20;
}
break;
//**************************************
case LCD_CLS:
//-- Clear the buffer
for(Icount=0;Icount<40;Icount++)
{
Buffer[Icount]=0;
}
//**************************************
case LCD_L0:
//-- Go to Start of 1st Line
Head=0;
//-- Also Clear the Line
for(Icount=0;Icount<20;Icount++) Buffer[Icount]=0;
break;
//**************************************
case LCD_L1:
//-- Go to Start of 2nd Line
Head=20;
//-- Also Clear the Line
for(Icount=20;Icount<40;Icount++) Buffer[Icount]=0;
break;
//**************************************
case LCD_SHOW:
//-- Update the Display
NewData=1;
break;
//**************************************
case LCD_GOTO:
//-- Put Cursor to location
GotoCommand=1;
//-- Indicated by next byte
break;
//**************************************
case LCD_PUTCH:
//-- Put next character directly to LCD
PutchCommand=1;
//-- By Passing the Buffer
break;
}
}
if(!OBF)
// Output Buffer has been read
{
PTBD=0x00;
// Put Null into buffer to indicate no key pressed
//
LastKeyPressed=0; // Allow Beep again on same key
}
TPM1CH2 = 0;
}
}
//******************* END OF GlobalInterrupt
//**********************************************************************
//KeyRead
//**********************************************************************
unsigned char KeyRead(void)
{
unsigned char line,data,result=0;
for(line=0;line <8;line++)
{
KeyAddr= line;
//-- Set Row To Read
DelayUs(KEYDELAY);
data = KeyInPort; //-- Read in the data
data = data >> 4; //-- shift to lower nibble
data
|= 0xF0;
//-- set upper nibble to 1s
data ^= 0xFF;
//-- invert everything (XOR)
if(data !=0)
{
result=line<<4; //-- Put line number in upper nibble
result+=data;
//-- Put Row Bit pattern in lower nibb
le
line=10;
//-- Terminate the loop
}
}
DelayUs(KEYDELAY); //-- We Bit More Delay
return(result);
//-- Return the result
}
//******************* END OF KeyRead
//**********************************************************************
//DecodeKey
//**********************************************************************
char DecodeKey(char keycode)
{
switch(keycode)
{
case 1:
return('D');
case 2:
return('E');
case 4:
return('0');
case 8:
return('C');
case 17:
return('R');
case 18:
return('3');
case 20:
return('2');
case 24:
return('1');
case 33:
return('L');
case 34:
return('6');
case 36:
return('5');
case 40:
return('4');
case 49:
return('U');
case 50:
return('9');
case 52:
return('8');
case 56:
return('7');
case 81:
return('M');
case 82:
return('a');
case 84:
return('b');
case 88:
return('c');
case 95:
//-- all function keys hit.
return(0xFF);
default:
break;
}
return(0);
}
//******************* END OF DecodeKey
//**********************************************************************
//DisplayData - Displays the Buffer on the LCD Display
//**********************************************************************
void DisplayData(void)
{
// unsigned char count;
lcd_clear();
//-- Clear the LCD
lcd_goto(0);
for(count=0;count<20;count++)
//-- Display the first line
{
if(Buffer[count]==0)
{
count=19;
//-- Check for end of string character
}
else
{
putch(Buffer[count]);
//-- Display Character on screen
}
}
lcd_goto(40);
//-- Move Cursor to second Line
for(;count<40;count++)
//-- Display the second line
{
if(Buffer[count]==0)
{
count=40;
//-- Check for end of string character
}
else
{
putch(Buffer[count]);
//-- Display Character on screen
}
}
// lcd_goto(21);
//-- Put cursor off the screen
}
//******************* END OF DisplayData
//**********************************************************************
//ScrollMessage
//**********************************************************************
void ScrollMessage(unsigned char row,const char Message[])
{
char TempS[21];
unsigned int MHead=0,Done=0;//,count;
if(row >1) row=1;
row=row*40;
while(Done==0)
{
for(count=0;count<20;count++)
{
TempS[count]=Message[MHead+count];
if(Message[MHead+count+1]==0) Done=1;
}
MHead++;
lcd_goto(row);
lcd_puts(TempS);
DelayMs(SCROLLDELAY);
}
}
//******************* END OF ScrollMessage