📄 1621_driver.c
字号:
/*HT1621 for KM3009/KM3005/KM3004 */
#include <REG2051.h> /* 8051 寄存器定义 */
#include "1621_driver.h"
#include "tel_equipment.h"
#include "AT24C08PAGE_Ok.H"
//ulong Time;
//uchar T[6];
//extern void ShowLCD(uchar *str);
/*the codes for 0~9 AbcdEF */
uchar code
TAB1[]={0xd7,0x50,0xe3,0xf1,0x74,0xb5,0xb7,0xd0,0xf7,0xf5,0xf6,0x37,0x23,0x73,0xa7,0xa6};
DELAY(int t){
int i,j;
for (i=0;i<t;i++)
for (j=0;j<t;j++);
}
WRITE_COM(uchar com) /*Write a command to LCD*/
{
uchar i;
bit Cy;
_CS = 0;
/*Write CMD code:100*/
_WR=0;
DELAY(1);
_DAT=1;
DELAY(1);
_WR=1;
DELAY(1);
_WR=0;
DELAY(1);
_DAT=0;
DELAY(1);
_WR=1;
DELAY(1);
DELAY(1);
_WR=0;
DELAY(1);
_DAT=0;
DELAY(1);
_WR=1;
for(i=0;i<8;i++) /*Write CMD */
{
Cy=com&0x80;
DELAY(1);
_WR=0;
DELAY(1);
_DAT=Cy;
DELAY(1);
_WR=1;
DELAY(1);
com=com<<1;
}
_WR=0;
DELAY(1);
_DAT=1;
DELAY(1);
_WR=1;
DELAY(1);
_CS=1;
}
/*------------------*/
WRITE_DAT(uchar addr,uchar dat) /*Write display data to LCD*/
{
uchar i;
bit Cy;
_CS = 0;
/*Write CMD code:101*/
DELAY(1);
_WR=0;
DELAY(1);
_DAT=1;
DELAY(1);
_WR=1;
DELAY(1);
_WR=0;
DELAY(1);
_DAT=0;
DELAY(1);
_WR=1;
DELAY(1);
_WR=0;
DELAY(1);
_DAT=1;
DELAY(1);
_WR=1;
DELAY(1);
addr=addr<<2;
for(i=0;i<6;i++) /*Write RAM address: xxA5~A0*/
{
Cy=addr&0x80;
_WR=0;
DELAY(1);
_DAT=Cy;
DELAY(1);
_WR=1;
DELAY(1);
addr=addr<<1;
}
for(i=0;i<4;i++) /*Write Display data :xxxxC0~C3*/
{
Cy=dat&0x80;
_WR=0;
DELAY(1);
_DAT=Cy;
DELAY(1);
_WR=1;
DELAY(1);
dat=dat<<1;
}
_CS=1;
}
DIS(uchar dat){
uchar i;
for(i=0;i<32;i++)
WRITE_DAT(i,dat);
}
SETUP_LCD(void){
DELAY(1000);
WRITE_COM(0x01); /*Enable system*/
WRITE_COM(0x18); /*CLOCK SOURCE IS 256kRC ON CHIP*/
WRITE_COM(0x29); /*BIAS=1/3 DUTY=1/4*/
WRITE_COM(0x03); /*Display on*/
DIS(0x00); /*Clear LCD*/
DELAY(200);
DIS(0xf0); //full lcd
DELAY(200); //
DIS(0x00); //clean lcd
DELAY(100);
}
void ClrLCD(void){
if(Showbit)DIS(0x00); /*Clear LCD*/
}
/*
addr 1,3,5,7 is battery 1,2,3,外壳
addr 9 is 未接
addr 17 is 呼入
addr 11 is 呼出
addr 19 is :
addr 23,25,27,29,31 is signal 4 3 2 1 天线
*/
/*
void ShowLCD(uchar signal,uchar battery,bit in,bit out,bit lose,bit sign,uchar addr,uchar *str,uchar unit){
uchar i;
DIS(0x00); //clean lcd
if (in)
WRITE_DAT(17,0x80); //show 呼入
if (out)
WRITE_DAT(11,0x80); //show 呼出
if (lose)
WRITE_DAT( 9,0x80); //show 未接
if (sign)
WRITE_DAT(19,0x80); //show :
if (signal > 4){
signal = 0;
}
i = 29;
WRITE_DAT(31,0x80); //clean l
while (signal){
WRITE_DAT(i,0x80); //clean l
i -= 2;
signal--;
}
if (battery > 3)
battery = 0;
i = 1;
WRITE_DAT(7,0x80);
while (battery){
WRITE_DAT(i,0x80); //clean l
i += 2;
battery--;
}
addr *= 2; //Show the nuber at the 0-0x0f
while (unit){
WRITE_DAT(addr, TAB1[*str]);
WRITE_DAT(addr+1, TAB1[*str] << 4);
addr += 2;
str++;
unit--;
// DELAY(100);
}
}
*/
void ShowLCD(bit sign,uchar addr,uchar *str,uchar unit){
if(Showbit){
DIS(0x00); //clean lcd
DELAY(10);
if (sign)
WRITE_DAT(19,0x80); //show :
addr *= 2; //Show the nuber at the 0-0x0f
while (unit){
WRITE_DAT(addr, TAB1[*str]);
WRITE_DAT(addr+1, TAB1[*str] << 4);
addr += 2;
str--;
unit--;
// DELAY(100);
}
}
}
/*showtime funtion is show clock at the LCD */
void showtime (void){
uchar addr,i;
if (times == times2)return;
times2 = times;
p[0] = (times%60) % 0x0a; //秒数个位 p[1] = (times%60) / 0x0a; //秒数个位
p[2] = ((times/60)%60) % 0x0a; //分钟数个位 p[3] = ((times/60)%60) / 0x0a; //分钟数十位
p[4] = ((times/3600)%60) % 0x0a; //小时数个位
p[5] = ((times/3600)%60) / 0x0a; //小时数十位
if(Showbit){
DIS(0x00); //clean lcd
addr = 16; //Show the nuber at the 0-0x0f
for(i=2;i<6;i++){
WRITE_DAT(addr, TAB1[p[i]]);
WRITE_DAT(addr+1, TAB1[p[i]] << 4);
addr += 2;
}
}
}
uchar ShowCountTime (ulong oldtime){
uchar i,addr;
while (polarity_bit ){
if (times == times2)continue;
times2 = times;
p[0] = (times - oldtime) % 60 %0x0a; //one sec
p[1] = (times - oldtime) % 60 /0x0a; //ten sec
p[2] = (times - oldtime)/60 % 60 %0x0a; //one min
p[3] = (times - oldtime)/60 % 60 /0x0a; //ten min
if(Showbit){
DIS(0x00); //clean lcd
addr = 16; //Show the nuber at the 0-0x0f
for(i=0;i<4;i++){
WRITE_DAT(addr, TAB1[p[i]]);
WRITE_DAT(addr+1, TAB1[p[i]] << 4);
addr += 2;
}
}
}
if(((times - oldtime) % 60) > 0)
oldtime = (times - oldtime) /60 +1;
else oldtime = (times - oldtime) /60;
return oldtime;
}
void showmoney (time){
uchar i,addr;
if (key[0] == 0x00){
if(key[1] == 0x00){
EEReadPage(&p[0],0,guoji_N,4);
}
else EEReadPage(&p[0],0,changtu_N,4);
}
else {
EEReadPage(&p[0],0,duantu_N,4);
}
//费率计算结果缓存_分 p[8]
//费率计算结果缓存_毛 p[7]
//费率计算结果缓存_元 p[6]
//费率计算结果缓存_十元 p[5]
//费率计算结果缓存_百元 p[4]
p[7] = p[3]*time/0x0a;
p[8] = p[3]*time%0x0a;
p[6] = (p[2]*time+p[7])/0x0a;
p[7] = (p[2]*time+p[7])%0x0a;
p[5] = (p[1]*time+p[6])/0x0a;
p[6] = (p[1]*time+p[6])%0x0a;
p[4] = (p[0]*time+p[5])/0x0a;
p[5] = (p[0]*time+p[5])%0x0a;
if(Showbit){
DIS(0x00); //clean lcd
addr = 16; //Show the nuber at the 0-0x0f
for(i=8;i>3;i--){
WRITE_DAT(addr, TAB1[p[i]]);
WRITE_DAT(addr+1, TAB1[p[i]] << 4);
addr += 2;
}
}
Showbit = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -