单片机课程设计电子钟实验.docx
《单片机课程设计电子钟实验.docx》由会员分享,可在线阅读,更多相关《单片机课程设计电子钟实验.docx(32页珍藏版)》请在冰豆网上搜索。
单片机课程设计电子钟实验
数字钟实验
一实验目的与要求
进一步熟悉I∧2C总线,掌握时钟芯片的使用;掌握使用液晶显示器显示时间
二实验内容
⒈PGF8563:
⑴实时时钟芯片,可记时时间1900-2099年,不具有周调整功能。
⑵数据传输采用I∧2C总线,固定片选地址;闹铃中断功能,可编程频率输出
⒉实验过程
读写PGF8563中的时间程序;在12864J液晶显示器显示时间
星期、日期
三实验步骤
1、主机连线说明:
E4区:
SDA----A3区:
P1.0
E4区:
SCL----A3区:
P1.1
A1区:
CS、RW、RS、CS1/2----A3区:
CS1、A0、A1、A2
2、初始化PCF8563,设置初始化时间(2005-07-01Fri12:
30:
00),读取时间数据;
调整读取的时间数据,转换为可以再图形液晶显示器上显示的数据,显示时间(年、月、日、星期、小时、分、秒
三实验原理图
四程序流程图
五程序清单
PCF8563时钟实验说明
;实验目的:
1.掌握时钟芯片的使用
;2.掌握使用液晶显示器显示时间
;实验内容:
1.读写PCF8563中的时间数据
;2.将时间显示在12864J液晶显示器上
;连线说明:
;PCF8563:
E4区-->A3区
;SDA-->P1.0,数据线
;SCL-->P1.1,时钟
;液晶12864J:
A1区-->A3区
;CS-->CS1(0F000H),片选
;RW-->A0,读/写控制端
;RS-->A1,数据/指令控制端
;CS1/2-->A2,左右半屏使能端
;*******************************************************
SECEQU30H;保存秒数据,用于检测秒变化
TEMPEQU31H;时间显示缓冲区
XSETEQU33H;时间起始显示行设置
YSETEQU34H;时间起始显示列设置
Time11EQU35H;数据缓冲区
WR_COM_AD_LXDATA0F004H;写左半屏指令地址
WR_COM_AD_RXDATA0F000H;写右半屏指令地址
WR_DATA_AD_LXDATA0F006H;写左半屏数据地址
WR_DATA_AD_RXDATA0F002H;写右半屏数据地址
RD_BUSY_ADXDATA0F001H;查忙地址
RD_DATA_ADXDATA0F003H;读数据地址
XEQU0B8H;起始显示行基址
YEQU040H;起始显示列基址
FirstLineEQU0C0H;起始显示行
SDABITP1.0;数据传输口
SCLBITP1.1;时钟
INTBITP3.2;闹钟/定时中断输出
;内部寄存器地址
CS1EQU00H;控制/状态寄存器1
CS2EQU01H;控制/状态寄存器2
SecondEQU02H;秒寄存器
MinuteEQU03H;分寄存器
HourEQU04H;时寄存器
DayEQU05H;天寄存器
WeekdayEQU06H;周寄存器
MouthEQU07H;月寄存器
YearEQU08H;年寄存器
MinuteAEQU09H;分闹铃寄存器
HourAEQU0AH;时闹铃寄存器
DayAEQU0BH;天闹铃寄存器
WeekdayAEQU0CH;周闹铃寄存器
COEQU0DH;时钟输出控制寄存器
TimerCtrlEQU0EH;定时控制寄存器
TimerEQU0FH;定时设置寄存器
;PCF8563的片选地址:
001H
PCF8563_WRITEEQU0A2H;写指令
PCF8563_READEQU0A3H;读指令
ORG0
LCALLMainINIT;主程序初始化
MAIN:
LCALLSec_Change;检测秒变化,给出判断标志位CY,1-有变化
JNCMAIN
LCALLTime_Read;读取时间
MOVSEC,TIME11;保存秒数据,用于检测秒变化
LCALLTime_Display;显示时间
JMPMAIN;循环进行实验内容介绍与PCF8563测试
;主程序初始化
MainINIT:
LCALLLCD_INIT;初始化液晶显示
LCALLPCF8563_INIT;PCF8563初始化
LCALLBackGround;显示背景,即显示不会变化的部分
LCALLTime_Read;读取时间,读取的时间数据存放在TIME中
MOVSEC,TIME11;保存秒数据,用于检测秒变化
LCALLTime_Display;显示时间
CLRF0;清秒变化标志
RET
;显示时间背景
BackGround:
MOVDPTR,#PIC2;显示"2"
MOVA,#2
MOVB,#0
LCALLByteDisL;显示1个字节子程序,左单屏
MOVDPTR,#PIC0;显示"0"
MOVA,#2
MOVB,#8
LCALLByteDisL
MOVDPTR,#BG1;第1行背景"-"
MOVA,#2;起始显示行:
第2行
MOVB,#32;起始显示列:
第16列
LCALLByteDisL
MOVDPTR,#BG1
MOVA,#2
MOVB,#56
LCALLByteDisL
MOVDPTR,#BG2;第2行背景":
"
MOVA,#4
MOVB,#48
LCALLByteDisL;显示1个字节子程序,左半屏
MOVDPTR,#BG2
MOVA,#4
MOVB,#8
LCALLByteDisR;显示1个字节子程序,右半屏
RET
BG1:
;"-"
DB000H,000H,000H,000H,000H,000H,000H,000H,001H,001H,001H,001H,001H,001H,001H,001H
BG2:
;":
"
DB000H,000H,000H,0C0H,0C0H,000H,000H,000H,000H,000H,000H,030H,030H,000H,000H,000H
;********************************
;时间显示
;********************************
;检测秒变化,给出判断标志F0,1-秒有变化;0-秒无变化
Sec_Change:
LCALLSec_Read;读取秒
CJNEA,SEC,Sec_Change_1;与前一次读取的秒比较,判断秒是否有变化
CLRC
RET
Sec_Change_1:
SETBC
RET
;时间显示,时间数据在TIME缓冲区中
Time_Display:
MOVA,TIME11;显示秒
ANLA,#0F0H
SWAPA
ACALLTEMPChange
MOVA,#4;起始显示行在第4行(从第0行开始算)
MOVB,#16;起始显示列在第16列(从第0列开始算)
LCALLByteDisR;显示秒,右半屏
MOVA,TIME11
ANLA,#0FH
LCALLTEMPChange
MOVA,#4
MOVB,#24
LCALLByteDisR
MOVA,TIME11+1;显示分
ANLA,#0F0H
SWAPA
LCALLTEMPChange;时间数据转换为图形显示数据
MOVA,#4;起始显示行在第4行(从第0行开始算)
MOVB,#56;起始显示列在第56列(从第0列开始算)
LCALLByteDisL;显示分,左半屏
MOVA,TIME11+1
ANLA,#0FH
LCALLTEMPChange
MOVA,#4
MOVB,#0
LCALLByteDisR
MOVA,TIME11+2;显示小时
ANLA,#0F0H
SWAPA
LCALLTEMPChange;时间数据转换为图形显示数据
MOVA,#4;起始显示行在第4行(从第0行开始算)
MOVB,#32;起始显示列在第32列(从第0列开始算)
LCALLByteDisL;显示小时,左半屏
MOVA,TIME11+2
ANLA,#0FH
LCALLTEMPChange
MOVA,#4
MOVB,#40
LCALLByteDisL
;显示日
MOVA,TIME11+3
ANLA,#0F0H
SWAPA
LCALLTEMPChange;时间数据转换为图形显示数据
MOVA,#2;起始显示行在第2行(从第0行开始算)
MOVB,#0;起始显示列在第0列(从第0列开始算)
LCALLByteDisR;显示日,右半屏
MOVA,TIME11+3
ANLA,#0FH
LCALLTEMPChange
MOVA,#2
MOVB,#8
LCALLByteDisR
;显示周
MOVA,TIME11+4
LCALLWeekChange;周数据转换为图形显示数据
MOVA,#2;起始显示行在第2行(从第0行开始算)
MOVB,#40;起始显示列在第32列(从第0列开始算)
LCALLWeekDisplay;显示周,右半屏
;显示月
MOVA,TIME11+5
ANLA,#0F0H
SWAPA
LCALLTEMPChange;时间数据转换为图形显示数据
MOVA,#2;起始显示行在第2行(从第0行开始算)
MOVB,#40;起始显示列在第40列(从第0列开始算)
LCALLByteDisL;显示月,左半屏
MOVA,TIME11+5
ANLA,#0FH
LCALLTEMPChange
MOVA,#2
MOVB,#48
LCALLByteDisL
;显示年
MOVA,TIME11+6
ANLA,#0F0H
SWAPA
LCALLTEMPChange;时间数据转换为图形显示数据
MOVA,#2;起始显示行在第2行(从第0行开始算)
MOVB,#16;起始显示列在第16列(从第0列开始算)
LCALLByteDisL;显示年,左半屏
MOVA,TIME11+6
ANLA,#0FH
LCALLTEMPChange
MOVA,#2
MOVB,#24
LCALLByteDisL
RET
;时间数据转换为图形显示数据的起始地址
TEMPChange:
RLA
MOVB,A
MOVDPTR,#Time_Tab
MOVCA,@A+DPTR
XCHA,B
INCA
MOVCA,@A+DPTR
MOVDPL,A
MOVDPH,B
RET
Time_Tab:
DWPIC0,PIC1,PIC2,PIC3,PIC4,PIC5,PIC6,PIC7,PIC8,PIC9
PIC0:
;--文字:
0--
DB000H,0E0H,010H,008H,008H,010H,0E0H,000H,000H,00FH,010H,020H,020H,010H,00FH,000H
PIC1:
;--文字:
1--
DB000H,010H,010H,0F8H,000H,000H,000H,000H,000H,020H,020H,03FH,020H,020H,000H,000H
PIC2:
;--文字:
2--
DB000H,070H,008H,008H,008H,088H,070H,000H,000H,030H,028H,024H,022H,021H,030H,000H
PIC3:
;--文字:
3--
DB000H,030H,008H,088H,088H,048H,030H,000H,000H,018H,020H,020H,020H,011H,00EH,000H
PIC4:
;--文字:
4--
DB000H,000H,0C0H,020H,010H,0F8H,000H,000H,000H,007H,004H,024H,024H,03FH,024H,000H
PIC5:
;--文字:
5--
DB000H,0F8H,008H,088H,088H,008H,008H,000H,000H,019H,021H,020H,020H,011H,00EH,000H
PIC6:
;--文字:
6--
DB000H,0E0H,010H,088H,088H,018H,000H,000H,000H,00FH,011H,020H,020H,011H,00EH,000H
PIC7:
;--文字:
7--
DB000H,038H,008H,008H,0C8H,038H,008H,000H,000H,000H,000H,03FH,000H,000H,000H,000H
PIC8:
;--文字:
8--
DB000H,070H,088H,008H,008H,088H,070H,000H,000H,01CH,022H,021H,021H,022H,01CH,000H
PIC9:
;--文字:
9--
DB000H,0E0H,010H,008H,008H,010H,0E0H,000H,000H,000H,031H,022H,022H,011H,00FH,000H
;周数据转换为图形显示数据的起始地址,存在TEMPDis中
WeekChange:
RLA
MOVB,A
MOVDPTR,#Week_Tab
MOVCA,@A+DPTR
XCHA,B
INCA
MOVCA,@A+DPTR
MOVDPL,A
MOVDPH,B
RET
Week_Tab:
DWWeek0,Week1,Week2,Week3,Week4,Week5,Week6
Week0:
;"Sun"
DB000H,070H,088H,008H,008H,008H,038H,000H,000H,038H,020H,021H,021H,022H,01CH,000H
DB080H,080H,000H,000H,000H,080H,080H,000H,000H,01FH,020H,020H,020H,010H,03FH,020H
DB080H,080H,000H,080H,080H,080H,000H,000H,020H,03FH,021H,000H,000H,020H,03FH,020H
Week1:
;"Mon"
DB008H,0F8H,0F8H,000H,0F8H,0F8H,008H,000H,020H,03FH,000H,03FH,000H,03FH,020H,000H
DB000H,000H,080H,080H,080H,080H,000H,000H,000H,01FH,020H,020H,020H,020H,01FH,000H
DB080H,080H,000H,080H,080H,080H,000H,000H,020H,03FH,021H,000H,000H,020H,03FH,020H
Week2:
;"Tue"
DB018H,008H,008H,0F8H,008H,008H,018H,000H,000H,000H,020H,03FH,020H,000H,000H,000H
DB080H,080H,000H,000H,000H,080H,080H,000H,000H,01FH,020H,020H,020H,010H,03FH,020H
DB000H,000H,080H,080H,080H,080H,000H,000H,000H,01FH,022H,022H,022H,022H,013H,000H
Week3:
;"Wed"
DB0F8H,008H,000H,0F8H,000H,008H,0F8H,000H,003H,03CH,007H,000H,007H,03CH,003H,000H
DB000H,000H,080H,080H,080H,080H,000H,000H,000H,01FH,022H,022H,022H,022H,013H,000H
DB000H,000H,000H,080H,080H,088H,0F8H,000H,000H,00EH,011H,020H,020H,010H,03FH,020H
Week4:
;"Thu"
DB018H,008H,008H,0F8H,008H,008H,018H,000H,000H,000H,020H,03FH,020H,000H,000H,000H
DB008H,0F8H,000H,080H,080H,080H,000H,000H,020H,03FH,021H,000H,000H,020H,03FH,020H
DB080H,080H,000H,000H,000H,080H,080H,000H,000H,01FH,020H,020H,020H,010H,03FH,020H
Week5:
;"Fri"
DB008H,0F8H,088H,088H,0E8H,008H,010H,000H,020H,03FH,020H,000H,003H,000H,000H,000H
DB080H,080H,080H,000H,080H,080H,080H,000H,020H,020H,03FH,021H,020H,000H,001H,000H
DB000H,080H,098H,098H,000H,000H,000H,000H,000H,020H,020H,03FH,020H,020H,000H,000H
Week6:
;"Sat"
DB000H,070H,088H,008H,008H,008H,038H,000H,000H,038H,020H,021H,021H,022H,01CH,000H
DB000H,000H,080H,080H,080H,080H,000H,000H,000H,019H,024H,022H,022H,022H,03FH,020H
DB000H,080H,080H,0E0H,080H,080H,000H,000H,000H,000H,000H,01FH,020H,020H,000H,000H
;显示周
WeekDisplay:
PUSHACC;A,B--X行,Y列序数
PUSHB
LCALLByteDisR;右半屏显示一个字节子程序
POPACC
ADDA,#8
MOVB,A
POPACC
PUSHACC
PUSHB
LCALLByteDisR;显示第2个字母
POPACC
ADDA,#8
MOVB,A
POPACC
LCALLByteDisR;显示第3个字母
RET
;液晶初始化
LCD_INIT:
MOVA,#3EH;初始化左半屏,关显示
LCALLWRComL;写指令子程序
MOVA,#FirstLine;设置起始显示行,第0行
LCALLWRComL
MOVA,#3EH;初始化右半屏,关显示
LCALLWRComR;写指令子程序
MOVA,#FirstLine;设置起始显示行,第0行
LCALLWRComR
LCALLLCDClear;清屏
MOVA,#3FH;开显示
LCALLWRComL
MOVA,#3FH;开显示
LCALLWRComR
RET
;清屏
LCDClear:
;清左半屏
MOVA,#0;起始行,第0行
MOVB,#0;起始列,第0列
LCDClearL1:
PUSHACC
MOVR7,#64
LCALLSETXYL;设置起始显示行列地址
LCDClearL2:
CLRA
LCALLWRDATAL
DJNZR7,LCDClearL2
POPACC
INCA
CJNEA,#8,LCDClearL1;共8行
;清右半屏
MOVA,#0;起始行,第0行
MOVB,#0;起始列,第0列
LCDClearR1:
PUSHACC
MOVR7,#64
LCALLSETXYR;设置起始显示行列地址
LCDClearR2:
CLRA
LCALLWRDATAR
DJNZR7,LCDClearR2
POPACC
INCA
CJNEA,#8,LCDClearR1;共8行
RET
;***************************************
;显示字体,显示一个数据要占用X行两行位置
;***************************************
;左半屏显示一个字节/字:
A-起始显示行序数X(0-7);B-起始显示列序数Y(0-63);DPTR-显示字数据首地址
ByteDisL:
MOVR7,#8;显示8个字节数据,用于显示一个英文/符号
JMPDispL
WordDisL:
MOVR7,#16;显示16字节数据,用于显示一个汉字
DispL:
PUSHACC
PUSH07H
LCALLSETXYL;设置起始显示行列地址
LCALLDisplayL;显示上半行数据
POP07H;DPTR指向下半部分字体数据区