LCD1602显示的篮球定时计分器的51单片机程序:
#include #define uint unsigned int #define uchar unsigned char uchar code table[]=".. Play ball! ...."; uchar code table1[]="Welcome to here!" ; sbit key_ST=P1^5; //功能键(开始/暂停) sbit key_A1=P1^0; //功能键(A队分数加1) sbit key_A2=P1^3; //功能键(A队分数加2) sbit key_1A=P1^6; //功能键(A队分数减1) sbit key_B1=P1^1; //功能键(B队分数加1) sbit key_B2=P1^4; //功能键(B队分数加2) sbit key_1B=P1^7; //功能键(B队分数减1) sbit key_EX=P1^2; //功能键(交换场地,A/B两队分数交换) sbit key_JS=P3^0; //功能键(比赛节数加1) sbit FMQ=P3^3; //蜂鸣器 sbit lcdrs=P3^5; //LCD显示的数据/命令选择端 sbit lcden=P3^4; //LCD显示的使能信号 uchar flag,ms,mg,ss,sg,ags,agg,bgs,bgg,num,num1,num2,js=1,C,D,t,min=0,time_fmq; int sec=12; void delayms(uint xms) //定义延时函数 { uint i,j; for(i=xms;i>0;i--) for(j=110;j>0;j--); } void write_data(uchar date) //定义为数据模式 { lcdrs=1; P0=date; delayms(5); lcden=1; delayms(5); lcden=0; } void write_com(uchar com) //定义为命令模式 { lcdrs=0; P0=com; delayms(5); lcden=1; delayms(5); lcden=0; } void lcd_init() //LCD显示屏的初始化 { lcden=0; write_com(0x38); write_com(0x0c); write_com(0x06); write_com(0x01); } void init() //LCD显示屏的初始化2(即输出“T-”、“Q-”、“A:”、“B:”) { lcden=0; write_com(0x82); write_data('T'); write_data('-'); write_com(0x8a); write_data('Q'); write_data('-'); write_com(0x80+0x43); write_data('A'); write_data(':'); write_com(0x80+0x49); write_data('B'); write_data(':'); } void init_start() //LCD显示屏的初始化2(即输出“T-”、“Q-”、“A:”、“B:”) { lcden=0; write_com(0x80+0x10); for(num2=0;num2<16;num2++) { write_data(table1[num2]); delayms(5); } write_com(0x80+0x50); for(num2=0;num2<17;num2++) { write_data(table[num2]); delayms(5); } for(num2=0;num2<16;num2++) { write_com(0x18); delayms(400); } } void display(uchar min,int sec,uchar C,uchar D,uchar js) //显示函数 { ss=sec/10; sg=sec%10; ms=min/10; mg=min%10; ags=C/10; agg=C%10; bgs=D/10; bgg=D%10; write_com(0x84); write_data(0x30+ms); write_data(0x30+mg); write_data(':'); write_data(0x30+ss); write_data(0x30+sg); write_com(0x8d-1); write_data(0x30+js); write_com(0x80+0x45); write_data(0x30+ags); write_data(0x30+agg); write_com(0x80+0x4b); write_data(0x30+bgs); write_data(0x30+bgg); } void main() { TMOD=0x11; //定义定时器0的工作方式为0001 TH0=(65536-45872)/256; //装初值 TL0=(65536-45872)%256; TH1=(65536-45872)/256; //装初值 TL1=(65536-45872)%256; EA=1; //打开总中断 ET0=1; //打开定时器0的中断 TR0=0; ET1=1; TR1=0; lcd_init(); init_start(); while(1) { TR1=0; if(key_ST==0) { delayms(5); if(key_ST==0) { FMQ=0; if(flag==0) { lcd_init(); init(); } flag=1; TR0=~TR0;
上一篇:基于单片机的超声波测距仪设计
下一篇:51单片机头文件reg51.h学习心得
推荐阅读最新更新时间:2024-10-31 19:21