/*****************************************************
Project: test lcd
MCU: HT67F40
Clock: 4M(Internal)
Author: Alex_wu
Date: 20111103
function: edit for segment0~17 + COM0~3 to drive LCD
option:
SysVolt: 3.0V
OSC: HIRC
WDT: enable
SysFreq: 4M
Vlcd: 3.0V
PB0/RES: I/O pin
Others select by user
******************************************************/
#include "HT67F40.h"
#include "lcd.h"
#pragma vector TM_ISR @0x14 //1ms timer
const u8 DigitCode[16] = {0x28,0x7e,0xa4,0x64,0x72,0x61,0x21,0x7c,0x20,0x60,0x30,0x23,0xa9,0x26,0xa1,0xb1}; //0~f
#pragma rambank0
u8 DISP8; //display buffer
u8 DISP9;
u8 DISP10;
u8 DISP11;
u8 DISP12;
u8 DISP13;
u8 DISP14;
u8 DISP15;
u8 DISP16;
u8 time2ms;
u8 SENDDATA;
u8 STATE;
u8 t500ms;
u16 t1s;
u8 hour;
u8 min;
u8 index;
u16 time1s_dis;
u16 time1s;
u8 tmin;
bit time2msflag;
bit t500msflag;
bit t1sflag;
bit poweronflag;
//----------------------main-------------------
void main()
{
Chip_Init();
for(_mp0 = 0x80; _mp0 < 0xff; _mp0++)
{
_iar0=0;
}
_dmbp0=1;
for(_mp1 = 0x80; _mp1 < 0xa0; _mp1++)
{
_iar1=0;
}
_dmbp0=0;
poweronflag=1;
while(1)
{
clrwdt1;
clrwdt2;
if(time2msflag)
{
time2msflag=0;
DIS_P();
_dmbp0=1;
_mp1 = 0x88;
_iar1= DISP8;
_mp1 = 0x89;
_iar1= DISP9;
_mp1 = 0x8a;
_iar1= DISP10;
_mp1 = 0x8b;
_iar1= DISP11;
_mp1 = 0x8c;
_iar1= DISP12;
_mp1 = 0x8d;
_iar1= DISP13;
_mp1 = 0x8e;
_iar1= DISP14;
_mp1 = 0x8f;
_iar1= DISP15;
_mp1 = 0x90;
_iar1= DISP16;
_dmbp0=0;
timer_p();
}
}
}
//---------------------------------------------
void Chip_Init()
{
_cp0c=0;
_cp1c=0;
_acerl=0;
_lcdout0=0; //seg0~7
_lcdout1=0; //seg8~15
_lcdout2=0b11111100; //seg16~17
_lcdctrl=0b01001111; //1/3 bias1/4 duty
_t0ae=1;
_ade=0;
_mf0e=1;
_tm0c0=0;
_tm0al=0b11101000; //1ms
_tm0ah=0b00000011;
_tm0c1=0b11000001;
_t0on=1;
_emi=1;
}
//---------------------------------------------
void timer_p()
{
if(t1sflag)
{
t1sflag=0;
if(++tmin>=60)
{
tmin=0;
if(++min>=60)
{
min=0;
if(++hour>=24)
hour=0;
}
}
}
}
//---------------------------------------------
void DIS_P()
{
if(STATE)
{
index=hour/10;
SENDDATA = ~DigitCode[index];
dis_p3();
index=hour%10;
SENDDATA = ~DigitCode[index];
dis_p4();
index=min/10;
SENDDATA = ~DigitCode[index];
dis_p5();
index=min%10;
SENDDATA = ~DigitCode[index];
dis_p6();
if(!t500msflag)
COL_C;
else
COL_S;
}
else
{
if(poweronflag)
{
F3_S;
G3_S;
E3_S;
DISP9=0x0f;
F4_S;
G4_S;
E4_S;
DISP11=0x0f;
COL_S;
F5_S;
G5_S;
E5_S;
DISP14=0x0f;
F6_S;
G6_S;
E6_S;
DISP16=0x0f;
}
else
{
DISP8=0;
DISP9=0;
DISP10=0;
DISP11=0;
DISP12=0;
DISP13=0;
DISP14=0;
DISP15=0;
DISP16=0;
STATE=1;
}
}
}
//-------------------
void dis_p3()
{
if(SENDDATA & 0x80)
C3_S;
else
C3_C;
if(SENDDATA & 0x40)
E3_S;
else
E3_C;
if(SENDDATA & 0x10)
D3_S;
else
D3_C;
if(SENDDATA & 0x08)
G3_S;
else
G3_C;
if(SENDDATA & 0x04)
F3_S;
else
F3_C;
if(SENDDATA & 0x02)
A3_S;
else
A3_C;
if(SENDDATA & 0x01)
B3_S;
else
B3_C;
}
//-------------------
void dis_p4()
{
if(SENDDATA & 0x80)
C4_S;
else
C4_C;
if(SENDDATA & 0x40)
E4_S;
else
E4_C;
if(SENDDATA & 0x10)
D4_S;
else
D4_C;
if(SENDDATA & 0x08)
G4_S;
else
G4_C;
if(SENDDATA & 0x04)
F4_S;
else
F4_C;
if(SENDDATA & 0x02)
A4_S;
else
A4_C;
if(SENDDATA & 0x01)
B4_S;
else
B4_C;
}
//-------------------
void dis_p5()
{
if(SENDDATA & 0x80)
C5_S;
else
C5_C;
if(SENDDATA & 0x40)
E5_S;
else
E5_C;
if(SENDDATA & 0x10)
D5_S;
else
D5_C;
if(SENDDATA & 0x08)
G5_S;
else
G5_C;
if(SENDDATA & 0x04)
F5_S;
else
F5_C;
if(SENDDATA & 0x02)
A5_S;
else
A5_C;
if(SENDDATA & 0x01)
B5_S;
else
B5_C;
}
//-------------------
void dis_p6()
{
if(SENDDATA & 0x80)
C6_S;
else
C6_C;
if(SENDDATA & 0x40)
E6_S;
else
E6_C;
if(SENDDATA & 0x10)
D6_S;
else
D6_C;
if(SENDDATA & 0x08)
G6_S;
else
G6_C;
if(SENDDATA & 0x04)
F6_S;
else
F6_C;
if(SENDDATA & 0x02)
A6_S;
else
A6_C;
if(SENDDATA & 0x01)
B6_S;
else
B6_C;
}
//---------------------------------------------
//1ms timer
//---------------------------------------------
void TM_ISR()
{
_t0af=0;
if(++time2ms>=2)
{
time2ms=0;
time2msflag=1;
if(poweronflag)
{
if(++time1s_dis>=1000) //筿陪2S
{
time1s_dis=0;
poweronflag=0;
}
}
else
{
if(++t500ms>=250)
{
t500ms=0;
t500msflag = ~t500msflag; //皗
if(++t1s>=2)
{
t1s=0;
t1sflag=1;
}
}
}
}
}
0.jpg (37.25 KB, 下載次數: 48)
下載附件
2018-5-2 17:22 上傳
全部資料51hei下載地址:
HT67FxxC語言控制LCD.zip
(22.31 KB, 下載次數: 15)
2018-5-2 17:01 上傳
點擊文件名下載附件
程序 下載積分: 黑幣 -5
|