📄 lcd.c
字号:
/* THIS SAMPLE CODE IS PROVIDED AS IS AND IS SUBJECT TO ALTERATIONS. FUJITSU */
/* MICROELECTRONICS ACCEPTS NO RESPONSIBILITY OR LIABILITY FOR ANY ERRORS OR */
/* ELIGIBILITY FOR ANY PURPOSES. */
/* (C) Fujitsu Microelectronics Europe GmbH */
/*****************************************************************************
* LCD.C
* Routines for the optional LCD on the Flash-CAN-100P-340
*****************************************************************************/
#include "mb90340.h"
#include "LCD.h"
/*****************************************************************************
* Initdisp : Resets the LCD and configures the I/F for 4-Bit bus
*****************************************************************************/
void LCDinitdisp(void)
{
PDR0=0; /* Port 0 Off*/
DDR0=0x0FF; /* Set Port 0 to output */
PDR0=0x34; /* Startup sequence */
LCDwait(200);
PDR0=0x30;
LCDwait(50000);
PDR0=0x34;
LCDwait(200);
PDR0=0x30;
LCDwait(50000);
PDR0=0x34;
LCDwait(200);
PDR0=0x30;
LCDwait(50000);
PDR0=0x24;
LCDwait(200);
PDR0=0x20;
LCDwait(500);
LCDoutb(0x028); /* Switch to 4-bit mode */
LCDoutb(LCD_CUROFF); /* No Cursor */
LCDoutb(LCD_NOSHIFT); /* No display shift */
LCDoutb(LCD_HOME); /* Cursor home */
LCDoutb(LCD_CLR); /* Display clear */
}
/*****************************************************************************
* OUTB sends one byte to the display
* PARAMETERS: 8-bit data
* RETURNS: None
*****************************************************************************/
void LCDoutb(unsigned char a)
{
unsigned char b;
b = (a & 0x70); /* upper nibble */
if (a & 0x80) /* check MSB */
{
b = (b | 0x01); /* set RS line */
};
b = (b | 0x04); /* set E line */
PDR0 = b; /* send to LCD */
LCDwait(10);
b = (b & 0xFB); /* clear E line */
PDR0 = b; /* send to LCD */
LCDwait(10);
b = (a & 0x0F); /* lower nibble */
b = b << 4; /* to upper nibble */
if (a & 0x80) /* check MSB */
{
b = (b | 0x01); /* set RS line */
};
b = (b | 0x04); /* set E line */
PDR0 = b; /* send to LCD */
LCDwait(10);
b = (b & 0xFB); /* clear E line */
PDR0 = b; /* send to LCD */
LCDbusy(); /* check LCD */
}
/*****************************************************************************
* BUSY polls the busy-line (waits for the LCD to be ready)
* PARAMETERS: None
* RETURNS: None
*****************************************************************************/
void LCDbusy(void)
{
unsigned char b;
PDR0 = 0; /* Port Off before reading ! */
b = 0x80;
while (b & 0x80) /* LCDwait for Busy-line */
{
DDR0 = 0x0F; /* set Bus as input to read LCD-busy-flag (LCD_D3) */
PDR0 = 0xF6; /* busy request */
LCDwait(200);
b = PDR0; /* read Port */
PDR0_P02 = 0;
PDR0_P02 = 1; /* toggle E */
PDR0_P02 = 0;
PDR0_P01 = 0;
DDR0 = 0xFF; /* reset Port to output */
}
}
/*****************************************************************************
* GOTO jump cursor to address
* PARAMETERS: address
* RETURNS: None
*****************************************************************************/
void LCDgoto(unsigned char address)
{
PDR0 = (address & 0xF0) | 0x04; /* upper nibble, set E line */
PDR0_P02 = 0; /* clear E line */
PDR0 = ((address<<4) & 0xF0) | 0x04; /* lowe nibble, set E line */
PDR0_P02 = 0; /* clear E line */
PDR0 = 0;
LCDbusy();
}
/*****************************************************************************
* PRINT displays a string
* PARAMETERS: pointer to string
* RETURNS: None
*****************************************************************************/
void LCDprint(char *Name2)
{
unsigned char c;
unsigned char b;
unsigned short i,l;
l=strlen(Name2);
for (i=0; i<l; i++) /* go through string */
{
c=(Name2[i]); /* pick char */
b=(c | 0x80);
LCDoutb(b);
}
}
/*****************************************************************************
* VERY PRIMITIVE DELAY LOOP *
*****************************************************************************/
void LCDwait(unsigned long i)
{
while(i--)
__asm("\tNOP");
}
/*****************************************************************************
* PRINTNUM shows integer value on LCD
* PARAMETERS: integer value
* RETURNS: None
*****************************************************************************/
void LCDprintnum(int n)
{
float x;
int l;
if (n < 10) /* only one digit value */
{
LCDoutb(0x0b0);
LCDoutb(0x0b0);
LCDoutb(0x0b0);
LCDoutb((n+48) | 128);
}
else if (n >= 10 && n<100) /* two digit value */
{
LCDoutb(0x0b0);
LCDoutb(0x0b0);
LCDoutb(((n/10)+48) | 128);
x = n-(10*(n / 10));
l = x;
LCDoutb((l+48) | 128);
}
else if (n >= 100 && n<1000) /* show three digits */
{
LCDoutb(0x0b0);
LCDoutb(((n/100)+48) | 128);
x = n-(100*(n / 100));
n = x;
LCDoutb(((n/10)+48) | 128);
x = n-(10*(n / 10));
l = x;
LCDoutb((l+48) | 128);
}
else if (n >= 1000) /* show four digits */
{
LCDoutb(((n/1000)+48) | 128);
x = n-(1000*(n / 1000));
n = x;
LCDoutb(((n/100)+48) | 128);
x = n-(100*(n / 100));
n = x;
LCDoutb(((n/10)+48) | 128);
x = n-(10*(n / 10));
l = x;
LCDoutb((l+48) | 128);
}
}
/*****************************************************************************
* DESCRIPTION: displays a x-digit Hex-number (as ASCII charcaters)
*
* PARAMETERS: Value and number of Hex-digits (e.g. FF = 2 Hex digits)
*
* RETURNS: NONE
*****************************************************************************/
void LCDprinthex(unsigned long n, unsigned char digits)
{
const char ASCII[] = {48,49,50,51,52,53,54,55,56,57,65,66,67,68,69,70};
unsigned char digit=0,div=0,i;
div=(4*(digits-1)); /* init shift divisor */
for (i=0;i<digits;i++)
{
digit = ((n >> div)&0xF); /* get hex-digit value */
LCDoutb((ASCII[digit]) | 128);
div-=4; /* next digit shift */
}
}
/*****************************************************************************
* Print Time displays time information (hh:mm:ss)
* PARAMETERS: hours, minutes, seconds
* RETURNS: None
*****************************************************************************/
void LCDprinttime(int h,int m,int s)
{
float x;
int l;
if (h < 10) /* hours : only one digit value */
{
LCDoutb(0x0b0);
LCDoutb((h+48) | 128);
}
else if (h >= 10 && h<100) /* two digit value */
{
LCDoutb(((h/10)+48) | 128);
x = h-(10*(h / 10));
l = x;
LCDoutb((l+48) | 128);
}
LCDoutb(58 | 128);
if (m < 10) /* minutes : only one digit value */
{
LCDoutb(0x0b0);
LCDoutb((m+48) | 128);
}
else if (m >= 10 && m<100) /* two digit value */
{
LCDoutb(((m/10)+48) | 128);
x = m-(10*(m / 10));
l = x;
LCDoutb((l+48) | 128);
}
LCDoutb(58 | 128);
if (s < 10) /* seconds : only one digit value */
{
LCDoutb(0x0b0);
LCDoutb((s+48) | 128);
}
else if (s >= 10 && s<100) /* two digit value */
{
LCDoutb(((s/10)+48) | 128);
x = s-(10*(s / 10));
l = x;
LCDoutb((l+48) | 128);
}
}
/*****************************************************************************
* Print Date displays date (DW DD-MM-YY)
* PARAMETERS: dw(dayofweek),dr(day),mr(month),yr(year)
* RETURNS: None
*****************************************************************************/
void LCDprintdate(int dw,int dr,int mr, int yr)
{
float x;
int l;
switch(dw) /* display day of week */
{
case 1:{LCDoutb(77 | 128); LCDoutb(79 | 128); break;} /* MO */
case 2:{LCDoutb(84 | 128); LCDoutb(85 | 128); break;} /* TU */
case 3:{LCDoutb(87 | 128); LCDoutb(69 | 128); break;} /* WE */
case 4:{LCDoutb(84 | 128); LCDoutb(72 | 128); break;} /* TH */
case 5:{LCDoutb(70 | 128); LCDoutb(82 | 128); break;} /* FR */
case 6:{LCDoutb(83 | 128); LCDoutb(65 | 128); break;} /* SA */
case 7:{LCDoutb(83 | 128); LCDoutb(85 | 128); break;} /* SU */
}
LCDoutb(32 | 128);
if (dr < 10) /* day in month : only one digit value */
{
LCDoutb(0x0b0);
LCDoutb((dr+48) | 128);
}
else if (dr >= 10 && dr<100) /* two digit value */
{
LCDoutb(((dr/10)+48) | 128);
x = dr-(10*(dr / 10));
l = x;
LCDoutb((l+48) | 128);
}
LCDoutb(46 | 128);
if (mr < 10) /* month : only one digit value */
{
LCDoutb(0x0b0);
LCDoutb((mr+48) | 128);
}
else if (mr >= 10 && mr<100) /* two digit value */
{
LCDoutb(((mr/10)+48) | 128);
x = mr-(10*(mr / 10));
l = x;
LCDoutb((l+48) | 128);
}
LCDoutb(46 | 128);
if (yr < 10) /* year : only one digit value */
{
LCDoutb(0x0b0);
LCDoutb((yr+48) | 128);
}
else if (yr >= 10 && yr<100) /* two digit value */
{
LCDoutb(((yr/10)+48) | 128);
x = yr-(10*(yr / 10));
l = x;
LCDoutb((l+48) | 128);
}
}
/*****************************************************************************
* MOVSCR displays a moving screen
* PARAMETERS: pointer to string
* RETURNS: None
*****************************************************************************/
void LCDmovscr(char *Name2, unsigned long delay)
{
int i,l;
l=strlen(Name2);
for (i=0; i<l; i++) /* go through string */
{
LCDprint(Name2); /* print string */
LCDwait(delay); /* wait ... */
Name2++; /* shift pointer one char ahead */
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -