本站小编为你精心准备了单片机电子秤设计软件程序清单参考范文,愿这些范文能点燃您思维的火花,激发您的写作灵感。欢迎深入阅读并收藏。
夜上海论坛;定义中文LCD液晶128X64的地址
夜上海论坛W_C_GLCDXDATA0E000H
W_D_GLCDXDATA0E001H
夜上海论坛R_B_GLCDXDATA0E002H
R_D_GLCDXDATA0E003H
夜上海论坛;-------------------------------------------------------
TIMER0DATA30H;延时时间的初值
夜上海论坛TIMER1DATA31H;调用延时子程序的次数
夜上海论坛DATA1DATA32H;点阵显示的变量1
DATA2DATA33H;点阵显示的变量2
夜上海论坛XDATA34H;X方向的位置
夜上海论坛YDATA35H;Y方向的位置
COUNTERDATA36H;计数器
夜上海论坛NDATA37H;行数变量
D1DATA38H;点变量1
夜上海论坛D2DATA39H;点变量1
ADDRDATA3AH;起始的显示位置
ADDR1DATA3BH;起始的显示位置临时变量
夜上海论坛N1DATA3CH;行数的临时变量
夜上海论坛;*******************************************************
;*主程序开始
夜上海论坛;*******************************************************
ORG0000H
AJMPSTART
ORG0030H
夜上海论坛START:CLRP1.0
SETBP1.1
MOVSP,#60H
夜上海论坛LCALLINITIAL_GLCD;调用LCD初始化
LCALLKAIJI;显示开机画面
LCALLDELAY500
LCALLDELAY500
LCALLDELAY500
LCALLTISHI;显示主界面
LCALLINI_8279
;------------------------------------------
夜上海论坛;判断是否继续
夜上海论坛;------------------------------------------
夜上海论坛KEY_A:MOVDPTR,#8101H;8101H为8279命令
MOVXA,@DPTR;读状态字
ANLA,#07H;判断低三位是否为0
CJNEA,#00H,LP1;不为0(有键按下)则跳转
SJMPKEY_A;为0(没键按下)则继续查询
LP1:MOVDPTR,#8100H;8100H为8279数据口
夜上海论坛MOVXA,@DPTR;读键值
夜上海论坛CJNEA,#0DBH,KEY_A;判断是否按D键
AJMPK1
K1:LCALLYUZHI;阈值设定
LCALLcelianjieguo;结果显示界面
LCALLCELIANGJIEGUO;结果显示
AJMP$
夜上海论坛;*******************************************************
;*主程序开始
;*******************************************************
夜上海论坛;=======================================================
;各界面显示内容
;=======================================================
夜上海论坛DHbr1:DB"欢迎使用"
DHbr2:DB"半桥电子秤"
夜上海论坛DHbr3:DB"设计人:xxx"
DHbr4:DB"时间:xxxx"
DHbr5:DB"****************"
夜上海论坛DHbr6:DB"设置报警上限"
夜上海论坛DHbr7:DB"确定"
DHbr8:DB"请按D键"
DHbr9:DB""
DHbr10:DB"报警上限重量:"
夜上海论坛DHbr11:DB".g"
夜上海论坛DHbr12:DB"确定(E)"
CELIANG1:DB"电子秤"
CELIANG2:DB"重量是:"
CELIANG3:DB".g"
CELIANG4:DB"返回(F)"
;=======================================================
;开机界面子程序
;=======================================================
KAIJI:MOVADDR1,#00H;第一行显示
MOVN1,#08H;数量8个
夜上海论坛MOVDPTR,#DHbr1;需要显示的汉字位置
CALLDHZ;调用汉字子序
MOVADDR1,#10H;第二行显示
MOVN1,#08H
夜上海论坛MOVDPTR,#DHbr2
CALLDHZ
MOVADDR1,#08H;第三行显示
MOVN1,#08H
MOVDPTR,#DHbr3
CALLDHZ
夜上海论坛MOVADDR1,#18H;第四行显示
MOVN1,#08H
夜上海论坛MOVDPTR,#DHbr4
CALLDHZ
RET
;=======================================================
;提示界面子程序
夜上海论坛;=======================================================
TISHI:LCALLCLEAR_GLCD;清除LCD显示屏幕
MOVADDR1,#00H
MOVN1,#08H
夜上海论坛MOVDPTR,#DHbr5
CALLDHZ
夜上海论坛MOVADDR1,#10H
MOVN1,#08H
MOVDPTR,#DHbr6
CALLDHZ
MOVADDR1,#08H
MOVN1,#08H
夜上海论坛MOVDPTR,#DHbr7
CALLDHZ
MOVADDR1,#18H
MOVN1,#08H
MOVDPTR,#DHbr8
CALLDHZ
RET
;=======================================================
;阈值设定界面子程序
夜上海论坛;=======================================================
夜上海论坛SHEDING:LCALLCLEAR_GLCD
MOVADDR1,#00H
MOVN1,#08H
夜上海论坛MOVDPTR,#DHbr9
CALLDHZ
MOVADDR1,#10H
MOVN1,#08H
MOVDPTR,#DHbr10
CALLDHZ
MOVADDR1,#08H
MOVN1,#08H
MOVDPTR,#DHbr11
CALLDHZ
MOVADDR1,#18H
MOVN1,#08H
MOVDPTR,#DHbr12
CALLDHZ
RET
;=======================================================
;测量界面子程序
夜上海论坛;=======================================================
celianjieguo:LCALLCLEAR_GLCD
MOVADDR1,#00H
MOVN1,#08H
MOVDPTR,#CELIANG1
CALLDHZ
MOVADDR1,#10H
MOVN1,#08H
MOVDPTR,#CELIANG2
CALLDHZ
夜上海论坛MOVADDR1,#08H
MOVN1,#08
MOVDPTR,#CELIANG3
CALLDHZ
MOVADDR1,#18H
MOVN1,#08
夜上海论坛MOVDPTR,#CELIANG4
CALLDHZ
RET
;=======================================================
夜上海论坛;8279初始化子程序
;=======================================================
夜上海论坛INI_8279:MOVDPTR,#8101H
MOVA,#00H
夜上海论坛MOVX@DPTR,A
MOVA,#32H
夜上海论坛MOVX@DPTR,A
MOVA,#0DFH
夜上海论坛MOVX@DPTR,A
RET
;=======================================================
;键盘设定阈值子程序
;=======================================================
夜上海论坛YUZHI:LCALLSHEDING
MOV44H,#00H;44H单元存按键次数,先清0
;******************键盘按键存储空间*******
MOV55H,#00H;存入四次按键值
夜上海论坛MOV56H,#00H
MOV57H,#00H
MOV58H,#00H
夜上海论坛MOV50H,#00H;存阈值百位
夜上海论坛MOV51H,#00H;存阈值十位和个位
MOV52H,#00H;存阈值小数位
夜上海论坛;*************************************************************
夜上海论坛KEY_09:MOVDPTR,#8101H;判断是否有键按下
MOVXA,@DPTR
ANLA,#07H
CJNEA,#00H,LPP1
AJMPKEY_09
;-------------------------------------------
;各个键的处理
;------------------------------------------
LPP1:MOVDPTR,#8100H
夜上海论坛MOVXA,@DPTR
B0:CJNEA,#0D8H,B1
AJMPKK0
夜上海论坛B1:CJNEA,#0D0H,B2
AJMPKK1
B2:CJNEA,#0D1H,B3
AJMPKK2
夜上海论坛B3:CJNEA,#0D2H,B4
AJMPKK3
夜上海论坛B4:CJNEA,#0C8H,B5
AJMPKK4
B5:CJNEA,#0C9H,B6
AJMPKK5
夜上海论坛B6:CJNEA,#0CAH,B7
AJMPKK6
夜上海论坛B7:CJNEA,#0C0H,B8
AJMPKK7
夜上海论坛B8:CJNEA,#0C1H,B9
AJMPKK8
B9:CJNEA,#0C2H,BE
AJMPKK9
夜上海论坛BE:CJNEA,#0DAH,YUZHI
AJMPKKE
KK0:MOV5BH,#00H;5BH存键值
夜上海论坛AJMPCOUNT_1
夜上海论坛KK1:MOV5BH,#01H
AJMPCOUNT_1
KK2:MOV5BH,#02H
AJMPCOUNT_1
夜上海论坛KK3:MOV5BH,#03H
AJMPCOUNT_1
KK4:MOV5BH,#04H
AJMPCOUNT_1
夜上海论坛KK5:MOV5BH,#05H
夜上海论坛AJMPCOUNT_1
KK6:MOV5BH,#06H
AJMPCOUNT_1
KK7:MOV5BH,#07H
AJMPCOUNT_1
夜上海论坛KK8:MOV5BH,#08H
AJMPCOUNT_1
KK9:MOV5BH,#09H
夜上海论坛AJMPCOUNT_1
KKE:AJMPEND_P
COUNT_1:MOVA,44H;44H存按键次数
INCA
MOV44H,A
夜上海论坛CJNEA,#05H,CW1;按键次数是否达到4次
AJMPYUZHI;五次按键则重设阈值
CW1:ADDA,#54H;键盘按键存储空间
MOVR0,A
CW2:CLRA
MOVA,5BH
MOV@R0,A
夜上海论坛LCALLPRO_SHOW
AJMPKEY_09
RET
;=========================================
;各次报警值按键处理子程序
夜上海论坛;=========================================
夜上海论坛PRO_SHOW:NOP
PR_1:CLRA;一次按键
MOVA,44H
夜上海论坛CJNEA,#01H,PR_2
MOVR0,#55H
MOVA,@R0
SUBBA,#05H
JNCSS
MOV51H,55H
MOVA,55H
夜上海论坛MOVADDR1,#0AH
LCALLSHUZIXIANSHI
SJMPEND_P
PR_2:CLRA;二次按键
MOVA,44H
夜上海论坛CJNEA,#02H,PR_3
CLRA
MOVA,55H
SWAPA
ADDA,56H
MOV51H,A
MOVA,55H
MOVADDR1,#09H
LCALLSHUZIXIANSHI
MOVA,56H
MOVADDR1,#0AH
LCALLSHUZIXIANSHI
AJMPEND_P
PR_3:CLRA;三次按键
MOVA,44H
夜上海论坛CJNEA,#03H,PR_4
CLRA
MOV50H,55H
MOVA,56H
SWAPA
ADDA,57H
MOV51H,A
MOVA,55H
MOVADDR1,#08H
夜上海论坛LCALLSHUZIXIANSHI
MOVA,56H
夜上海论坛MOVADDR1,#09H
LCALLSHUZIXIANSHI
MOVA,57H
夜上海论坛MOVADDR1,#0AH
夜上海论坛LCALLSHUZIXIANSHI
SJMPEND_P
PR_4:CLRA;四次按键
MOVA,58H
SWAPA
MOV52H,A
SWAPA
夜上海论坛MOVADDR1,#0CH
LCALLSHUZIXIANSHI
SJMPEND_P
END_P:RET
夜上海论坛SS:LJMPYUZHI
;=============================================================
;结果显示子程序
夜上海论坛;=============================================================
夜上海论坛CELIANGJIEGUO:LCALLADC0809;调用0809采样程序
夜上海论坛LCALLZHH;调用转换程序
MOVADDR1,#08H;采数据送LCD显示
MOVA,40H
夜上海论坛LCALLSHUZIXIANSHI
MOVADDR1,#09H
MOVA,41H
SWAPA
LCALLSHUZIXIANSHI
夜上海论坛MOVADDR1,#0AH
MOVA,41H
夜上海论坛LCALLSHUZIXIANSHI
夜上海论坛MOVADDR1,#0CH
MOVA,43H
SWAPA
LCALLSHUZIXIANSHI
CALLDELAY500;调用延时
夜上海论坛CALLBJ;判断是否超过阈值,超过则报警
夜上海论坛;------------------------------------------
夜上海论坛;F键判断是否返回提示界面
;------------------------------------------
KEY_F:MOVDPTR,#8101H
MOVXA,@DPTR
ANLA,#07H
夜上海论坛CJNEA,#00H,LP2
夜上海论坛SJMPCELIANGJIEGUO
夜上海论坛LP2:MOVDPTR,#8100H
MOVXA,@DPTR
CJNEA,#0D9H,CELIANGJIEGUO;判断是否按F键
SETBP1.1
CLRP1.0
AJMPK1
夜上海论坛;=======================================================
;报警子程序
;=======================================================
BJ:MOVR1,#50H
MOVA,@R1
CLRC
SUBBA,40H
JCWARNING
JZCOMP1
SETBP1.1
CLRP1.0
RET
夜上海论坛COMP1:INCR1
MOVA,@R1
CLRC
SUBBA,41H
JCWARNING
JZCOMP2
SETBP1.1
CLRP1.0
RET
夜上海论坛COMP2:INCR1
MOVA,@R1
CLRC
SUBBA,43H
JCWARNING
SETBP1.1
CLRP1.0
RET
夜上海论坛WARNING:CLRP1.1
SETBP1.0
RET
;=======================================================
;0809采样程序
ADC0809:PUSHDPL
PUSHDPH
PUSHACC
MOVDPTR,#W_D_0809;AD0809的启动地址
MOVA,#00H
MOVX@DPTR,A;0通道
LCALLDELAY01;延时100US
MOVXA,@DPTR;读出A/D的结果
夜上海论坛MOV3FH,A;暂存
POPACC
POPDPH
POPDPL
RET
夜上海论坛;=======================================================
;转换子程序:3FH的内容(A/D采样的结果)*(5V/256(FFH))=十进制结果;40H,41H.例如:3FH=0FFH,那么程序执行后:40H=04H,41H=99H既4.99V
夜上海论坛;=======================================================
ZHH:PUSHPSW
PUSHACC
SETBRS0
MOVA,#4eH
MOVB,3FH
MULAB
MOVR6,B
MOVR7,A
HB2:CLRA
MOVR3,A
MOVR4,A
MOVR5,A
MOVR2,#10H
夜上海论坛HB3:MOVA,R7
RLCA
MOVR7,A
MOVA,R6
RLCA
MOVR6,A
MOVA,R5
ADDCA,R5
DAA
MOVR5,A
MOVA,R4
ADDCA,R4
DAA
MOVR4,A
MOVA,R3
ADDCA,R3
MOVR3,A
DJNZR2,HB3
MOV40H,R3
MOV41H,R4
MOV43H,R5
POPACC
POPPSW
RET
夜上海论坛;=======================================================
;点阵式LCD(128X64)模块显示部分子程序;以下是公共的程序:
夜上海论坛;=======================================================
;LCD初始化子程序
;=========================================
INITIAL_GLCD:PUSHACC
夜上海论坛MOVA,#30H;功能设定
CALLCOMMAND_GLCD
夜上海论坛MOVA,#30H;功能设定
CALLCOMMAND_GLCD
夜上海论坛MOVA,#30H;功能设定
夜上海论坛CALLCOMMAND_GLCD
MOVA,#06H;显示器控制:游标不显示;
CALLCOMMAND_GLCD
MOVA,#01H;清除显示器
CALLCOMMAND_GLCD
MOVA,#0CH;进入模式设定
CALLCOMMAND_GLCD
POPACC
RET
;=========================================
夜上海论坛;汉字显示子程序(16X16点阵)
;=========================================
DHZ:MOVADDR,ADDR1;开始行位置
MOVB,N1;显示数量
DHZ1:MOVA,ADDR;
夜上海论坛ORLA,#80H;送显示地址
夜上海论坛LCALLCOMMAND_GLCD;调写命令子程序
DHZ2:CLRA
MOVCA,@A+DPTR;查找汉字的高位码
INCDPTR
LCALLWRITE_GLCD;送显示
CLRA
MOVCA,@A+DPTR;查找汉字的低位码
INCDPTR
LCALLWRITE_GLCD;送显示
DJNZB,DHZ2
RET
;=========================================
;数字显示子程序
;=========================================
夜上海论坛SHUZIXIANSHI:MOV42H,A
夜上海论坛MOVADDR,ADDR1;开始行位置
MOVA,ADDR;
ORLA,#80H;送显示地址
LCALLCOMMAND_GLCD
MOVA,42H
夜上海论坛;------------------------------------------
;将ACC内容,以十六进制值显示
夜上海论坛;------------------------------------------
HEX_LCD:PUSHDPH
PUSHDPL
PUSHACC
ANLA,#0FH
MOVDPTR,#ASCII_CODE;DPTR指到ASCII_CODE
MOVCA,@A+DPTR;取得ASCII码
CALLWRITE_GLCD;写到LCD
POPACC
POPDPL
POPDPH
RET
ASCII_CODE:DB''''0123456789ABCDEF''''
;=========================================
;检查LCD忙碌标志
;=========================================
夜上海论坛CHKBUSY_GLCD:PUSHDPH
PUSHDPL
PUSHACC
夜上海论坛MOVDPTR,#R_B_GLCD
夜上海论坛CHK:MOVXA,@DPTR
JBACC.7,CHK;判别是不是忙?
POPACC
POPDPL
POPDPH
RET
夜上海论坛;=========================================
;写命令到GLCD
夜上海论坛;=========================================
夜上海论坛COMMAND_GLCD:PUSHDPH
PUSHDPL
CALLCHKBUSY_GLCD;判别是不是忙?
MOVDPTR,#W_C_GLCD
夜上海论坛MOVX@DPTR,A;写入命令
POPDPL
POPDPH
RET
;=========================================
;写资料到GLCD
夜上海论坛;=========================================
WRITE_GLCD:PUSHDPH
PUSHDPL
CALLCHKBUSY_GLCD;判别是不是忙?
MOVDPTR,#W_D_GLCD;写入数据
MOVX@DPTR,A
POPDPL
POPDPH
RET
;=========================================
夜上海论坛;清除LCD的显示幕
夜上海论坛;=========================================
CLEAR_GLCD:PUSHACC
MOVA,#01H;清除显示器
CALLCOMMAND_GLCD
POPACC
RET
;=======================================================
;延时子程序
;=======================================================
夜上海论坛DELAY:PUSHTIMER1;延时TIMER1*1msfor12MHz
PUSHTIMER0
夜上海论坛DELAY1:MOVTIMER0,#250;时间为4*1μS
DELAY2:NOP;1个周期
NOP;1个周期
DJNZTIMER0,DELAY2;2个周期
DJNZTIMER1,DELAY1
POPTIMER0
POPTIMER1
RET
NOP
夜上海论坛;------------------------------------------
;延时1ms
;------------------------------------------
夜上海论坛DELAY01:NOP
PUSHTIMER1
MOVTIMER1,#01H
LCALLDELAY
POPTIMER1
RET
NOP
;------------------------------------------
;延时500ms
;------------------------------------------
DELAY500:NOP
PUSHTIMER1
MOVTIMER1,#250
LCALLDELAY
LCALLDELAY
POPTIMER1
RET
NOP