美章网 资料文库 单片机电子秤设计软件程序清单范文

单片机电子秤设计软件程序清单范文

本站小编为你精心准备了单片机电子秤设计软件程序清单参考范文,愿这些范文能点燃您思维的火花,激发您的写作灵感。欢迎深入阅读并收藏。

单片机电子秤设计软件程序清单

程序清单

;定义中文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