本帖最后由 芯圣电子官方QQ 于 2023-7-24 14:15 编辑
显示效果不错,代码有点烂,见谅
液晶原理图,接线图
代码
#define ALLOCATE_EXTERN
#include "HC89F0541.H"
unsigned char guc_DisFreshStep = 0;
unsigned char code COM0_SEG[]={1,0,1,1,0,1,1,0,1,1};
unsigned char code COM1_SEG[]={3,2,1,2,2,2,3,2,3,2};
unsigned char code COM2_SEG[]={1,0,2,2,3,3,3,0,3,3};
unsigned char code COM3_SEG[]={3,2,3,3,2,1,1,3,3,3};
bit dp;
unsigned char miao,fen;
unsigned int num,h;
unsigned char C1,C2,C3,C4,C5,C6,dpw;
void LCD_Display()
{
if(dp==0)dpw=2; else dpw=0; //冒号闪烁
switch(guc_DisFreshStep)
{
case 0: LCDCON =LCDCON^0x10;
guc_DisFreshStep = 1;
P0_0 = 1;
P0_1 = 0;
P0_2 = 0;
P0_3 = 0;
P1 = ((COM0_SEG[C4]+dpw)<<6) | (COM0_SEG[C3]<<4) | (COM0_SEG[C2]<<2) | COM0_SEG[C1];
P3 = (COM0_SEG[C6]<<2) | COM0_SEG[C5];
break;
case 1: guc_DisFreshStep = 2;
P0_0 = 0;
P0_1 = 1;
P0_2 = 0;
P0_3 = 0;
P1 = (COM1_SEG[C4]<<6) | (COM1_SEG[C3]<<4) | (COM1_SEG[C2]<<2) | COM1_SEG[C1];
P3 = (COM1_SEG[C6]<<2) | COM1_SEG[C5];
break;
case 2: guc_DisFreshStep = 3;
P0_0 = 0;
P0_1 = 0;
P0_2 = 1;
P0_3 = 0;
P1 = (COM2_SEG[C4]<<6) | (COM2_SEG[C3]<<4) | (COM2_SEG[C2]<<2) | COM2_SEG[C1];
P3 = (COM2_SEG[C6]<<2) | COM2_SEG[C5];
break;
case 3: guc_DisFreshStep = 0;
P0_0 = 0;
P0_1 = 0;
P0_2 = 0;
P0_3 = 1;
P1 = (COM3_SEG[C4]<<6) | (COM3_SEG[C3]<<4) | (COM3_SEG[C2]<<2) | COM3_SEG[C1];
P3 = (COM3_SEG[C6]<<2) | COM3_SEG[C5];
break;
default:guc_DisFreshStep = 0;
break;
}
}
void main()
{
/************************************系统初始化****************************************/
CLKSWR = 0x53; //选择内部高频RC为系统时钟,内部高频RC 8分频,Fosc=4MHz
CLKDIV = 0x01; //Fosc 1分频得到Fcpu,Fcpu=4MHz
TCON1 = 0x01; //Tx0定时器时钟为Fosc
TMOD = 0x00; //16位重装载定时器/计数器
//T0定时时间500微秒@4MHz
TH0 = 0xF8; //设置定时初值
TL0 = 0x30; //设置定时初值
IE |= 0x02; //打开T0中断
TCON |= 0x10; //使能T0
EA = 1; //打开总中断
/***********************************LCD配置初始化**************************************/
BORC &=~ 0x80; //关闭BOR节省功耗
LCDCON = 0xE8; //使能LCD,50K电阻,1/3bias
COMP0EN = 0x0F; //COM使能P00-P03
SEGP1EN = 0xFF; //SEG口使能P10-P17
SEGP3EN = 0x0F; //SEG口使能P30-P33
while(1)
{
C1=h%10000/1000;
C2=h%1000/100;
C3=h%100/10;
C4=h%10;
C5=fen%100/10;
C6=fen%10;
}
}
/***************************************************************************************
* @说明 T0中断服务函数
* @参数 无
* @返回值 无
* @注 无
***************************************************************************************/
void TIMER0_Rpt(void) interrupt TIMER0_VECTOR
{
LCD_Display();
num++;
if(num==1000)
{
num=0; dp=~dp;
miao++;
if(miao==120)
{
miao=0; fen++;
if(fen==60)
{
fen=0; h++;
}
}
}
}
|
|