本站小編為你精心準備了單片機電子秤設計軟件程序清單參考范文,愿這些范文能點燃您思維的火花,激發您的寫作靈感。歡迎深入閱讀并收藏。
;定義中文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