📄 lcd.c
字号:
/************************************************************************/
/* Renesas System Solutions (Beijing) Co., LTD. */
/* All rights reserved. */
/* */
/* File Name : LCD.c */
/* Description : */
/* */
/* Current Version : 1.0 */
/* Designer : Feng Jun */
/* Start Date : 2006-11-6 */
/* Complete Date : 2006-11-22 */
/* */
/* Lastest Version : */
/* Designer : */
/* Start Date : */
/* Complete Date : */
/************************************************************************/
#include <stdio.h>
#include "LCD.h"
#include "main.h"
extern char eeprombuffer[32];
union byte_def senddataaddr;
#define senddata senddataaddr.byte
#define a0 senddataaddr.bita.b0
#define a1 senddataaddr.bita.b1
#define a2 senddataaddr.bita.b2
#define a3 senddataaddr.bita.b3
#define a4 senddataaddr.bita.b4
#define a5 senddataaddr.bita.b5
#define a6 senddataaddr.bita.b6
#define a7 senddataaddr.bita.b7
union byte_2 hex2bcdaddr;
#define hex2bcd hex2bcdaddr.word
#define hex2bcdH hex2bcdaddr.byte.high
#define hex2bcdL hex2bcdaddr.byte.low
char sendbuffer[6];
char conbuffer[6];
extern void EEPROMReadNBytes(char *buffer, char n, char addr);
/*************************************************************************
Name: Delay4nop
Parameters: None
Returns: None
Description: Delay4nop
*************************************************************************/
void Delay4nop(void)
{
nop_instruction();
nop_instruction();
nop_instruction();
nop_instruction();
}
/*************************************************************************
Name: LCDSendBit
Parameters: None
Returns: None
Description: Send one bit to LCD
Data will be sent to LCD when a rising edge happens at CLK
*************************************************************************/
void LCDSendBit(void)
{
io_LCDCLK = 0;
Delay4nop();
io_LCDCLK = 1;
Delay4nop();
}
/*************************************************************************
Name: LCDSend8bit
Parameters: None
Returns: None
Description: Send 8bit data to LCD
*************************************************************************/
void LCDSend8bit(void)
{
io_LCDDI = a7;
LCDSendBit();
io_LCDDI = a6;
LCDSendBit();
io_LCDDI = a5;
LCDSendBit();
io_LCDDI = a4;
LCDSendBit();
io_LCDDI = a3;
LCDSendBit();
io_LCDDI = a2;
LCDSendBit();
io_LCDDI = a1;
LCDSendBit();
io_LCDDI = a0;
LCDSendBit();
}
/*************************************************************************
Name: LCDReset
Parameters: None
Returns: None
Description: LCD reset
*************************************************************************/
void LCDReset(void)
{
io_LCDCS = 1; /* Disable LCD */
Delay4nop();
io_LCDCS = 0; /* Enable LCD */
/* Send command "100" */
io_LCDDI = 1;
LCDSendBit();
io_LCDDI = 0;
LCDSendBit();
io_LCDDI = 0;
LCDSendBit();
senddata = 0; /* Turn off both system oscillator and LCD bias generator */
LCDSend8bit(); /* Command is 9bit */
LCDSendBit();
senddata = 2; /* Turn off LCD output */
LCDSend8bit();
LCDSendBit();
senddata = 1; /* Turn on system oscillator */
LCDSend8bit();
LCDSendBit();
senddata = 3; /* Turn on LCD output */
LCDSend8bit();
LCDSendBit();
senddata = 0x29; /* Set LCD mode */
LCDSend8bit();
LCDSendBit();
}
/*************************************************************************
Name: DisableLCD
Parameters: None
Returns: None
Description: Disable LCD
*************************************************************************/
void DisableLCD(void)
{
io_LCDCS = 1; /* Disable LCD */
Delay4nop();
io_LCDCS = 0; /* Enable LCD */
/* Send command "100" */
io_LCDDI = 1;
LCDSendBit();
io_LCDDI = 0;
LCDSendBit();
io_LCDDI = 0;
LCDSendBit();
senddata = 0; /* Turn off both system oscillator and LCD bias generator */
LCDSend8bit(); /* Command is 9bit */
LCDSendBit();
senddata = 2; /* Turn off LCD output */
LCDSend8bit();
LCDSendBit();
}
/*************************************************************************
Name: LCDWriteRAM
Parameters: None
Returns: None
Description: Write all the data to RAM, successive address writing mode
*************************************************************************/
void LCDWriteRAM(void)
{
int i;
io_LCDCS = 1; /* Disable LCD */
Delay4nop();
io_LCDCS = 0; /* Enable LCD */
/* Send ID "101" */
io_LCDDI = 1;
LCDSendBit();
io_LCDDI = 0;
LCDSendBit();
io_LCDDI = 1;
LCDSendBit();
/* Send 6bit start address */
io_LCDDI = 0;
LCDSendBit();
LCDSendBit();
LCDSendBit();
LCDSendBit();
LCDSendBit();
LCDSendBit();
/* Send 5byte data */
for (i=0; i<6; i++)
{
senddata = sendbuffer[i];
LCDSend8bit();
}
io_LCDCS = 1; /* DIsable LCD */
}
/*************************************************************************
Name: TransferHexToBCD
Parameters: None
Returns: None
Description: Transfer hex to BCD
*************************************************************************/
void TransferHexToBCD(int data)
{
sprintf(conbuffer, "%d", data);
}
/*************************************************************************
Name: DispConvert
Parameters: None
Returns: None
Description:
*************************************************************************/
char DispConvert(char data)
{
switch ( data )
{
case '0':
return 0xfa; /* 0: '11111010' */
case '1':
return 0x0a; /* 1: '00001010' */
case '2':
return 0xbc; /* 2: '10111100' */
case '3':
return 0x9e; /* 3: '10011110' */
case '4':
return 0x4e; /* 4: '01001110' */
case '5':
return 0xd6; /* 5: '11010110' */
case '6':
return 0xf6; /* 6: '11110110' */
case '7':
return 0x8a; /* 7: '10001010' */
case '8':
return 0xfe; /* 8: '11111110' */
case '9':
return 0xde; /* 9: '11011110' */
default :
return 0; /* Blank */
}
}
/*************************************************************************
Name: LCDDisplay
Parameters: None
Returns: None
Description: Display some infomation on LCD such as surplus and the
status of water meter
*************************************************************************/
void LCDDisplay(void)
{
int i;
int j = 0;
/* Get data that to be shown */
// EEPROMReadNBytes(eeprombuffer, 40, 0);
EEPROMReadNBytes(sendbuffer, 2, 0x14);
hex2bcdH = sendbuffer[0];
hex2bcdL = sendbuffer[1];
if (hex2bcd == 0)
{
EEPROMReadNBytes(sendbuffer, 2, 0x1a);
hex2bcdH = sendbuffer[0];
hex2bcdL = sendbuffer[1];
B_dispnegative = 1;
}
TransferHexToBCD( hex2bcd );
for (i=0; i<4; i++)
{
if (conbuffer[3-i] == 0)
{
sendbuffer[1+i] = 0;
}
else
{
sendbuffer[4-j] = DispConvert(conbuffer[3-i]);
j++;
}
}
sendbuffer[0] = 0;
sendbuffer[5] = 0x80;
if (B_dispnegative == 1)
{ /* Display negative */
for (i=0; i<4; i++)
{
if (sendbuffer[i]==0 && sendbuffer[i+1]!=0 && sendbuffer[i+1]!=0xfa)
{
sendbuffer[i] = 0x04; /* '-': '00000100' */
}
}
}
if (B_dispvalve == 1)
{ /* Display valve closed */
sendbuffer[4] |= 0x01; /* Display '关阀' */
}
if (B_errorcard == 1)
{ /* Display error card */
sendbuffer[5] |= 0x01; /* Display '读卡错' */
}
if (B_warning == 1)
{ /* Display warning */
sendbuffer[5] |= 0x02; /* Display '交费' */
}
if (B_lowvoltage == 1)
{ /* Display low voltage */
sendbuffer[5] |= 0x08; /* Display '电压低' */
}
/* test */
// sendbuffer[0] = 0xfa; /* 0 */
// sendbuffer[1] = 0x0a; /* 1 */
// sendbuffer[2] = 0xbc; /* 2 */
// sendbuffer[3] = 0x9e; /* 3 */
// sendbuffer[4] = 0x4e; /* 4 */
// sendbuffer[5] = 0x10; /* 5 */
/* test end */
/* Send data to LCD */
ioD_LCDCLK = 1; /* Set direction */
ioD_LCDDI = 1;
ioD_LCDCS = 1;
LCDReset(); /* LCD reset */
LCDWriteRAM(); /* Write LCD's RAM */
g_statusA = 4; /* To detect flow */
/* test */
// B_openvalve = 1;
// B_closevalve = 1;
/* test end */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -