|||
我是一名叫什么来着的?嵌入式业余爱好者吧。
我也了解过几家公司的单片机,像51、义隆、十速、中颖,这里估且说成是了解封装吧;
按照网络上的词汇讲,我是一名电工,嵌入式这个架(招)式,现在的我还是一个新手,充其量算是一个入门者,排在嵌入式最底层的那一层膜上。
我在业余学着写程序时都是一个整体的一个程序学着写;这样在查看时,得用鼠标从到头到尾拖拉着看。那感觉像极了电线杆。
之前,写个两个程序:
一个是带4分钟睡眠功能的单键的三种控制LCD计时显示的模式,另一个是七彩灯的30分30秒的控制程序,也做过样品,反正算是 演示过吧。
之外,我还一口气这样写下来,写过24小时的电子钟,0~9数字的拉幕,很基本的秒表;
在工作中,看到他们在写程序时,就像我画板一样的调用元件封装;
哇噻!遇着高手了,那感觉是。当当的。
这是我自写的一个DEMO,算是DEMO吧!因为这个框架还是不错的(自我感觉呀),这也是第一次这样写。
程序是由一个主程序和几个小部份程序分开写成的。主是要掌握好几个小程序的入口和出口,不能混淆的。
这样,觉得对入门者,还是有一点帮助的。
;--------------------------------
include f:\杂文件\中颖单片机\sh66p12.h
;--------------------------------
ORG 0000H
jmp r_start
;--------------------------------
org 0001h
rtni ;jmp ex_int
org 0002h
jmp int_time0
org 0003h
rtni ;jmp int_time1
org 0004h
rtni ;jmp int_pbc
;------------------------------
org 0005h
;------------------------------
include keyscan.asm
include display.asm
;------------------------------
;-------------------------
int_time0:
sta acc_bak
ldi irq,0
adim sec_1,01
daa sec_1
ldi temp,0
adcm sec_2,0
daa sec_2
ldi temp,0
adcm min_1,0
daa min_1
ldi temp,0
adcm min_2,0
sbi min_2,06
bnz inttime0_end
ldi temp,0
ldi min_2,0
inttime0_end:
ldi ie,0100b
lda acc_bak
rtni
;-------------------------
;--------------------------------
r_start:
nop
nop
nop
nop
;--------------------------------
clearram:
ldi dpl,00h
ldi dpm,02h
ldi dph,00h
?clrinx:
ldi inx,00h
adim dpl,01h
bnc ?clrinx
adim dpm,01h
andim dpm,07h
sbi dpm,05h
bnc ?clrinx
;--------------------------------
ldi tbr,1
ldi setting,0001b
ldi ace,0000b
ldi duty,1
ldi pa,1111b
ldi pb,1111b
ldi pc,1111b
;--------------------------------
ldi cyc,04
ldi dpl,0
ldi dpm,0
ldi dph,06
clr_lcd:
ldi inx,0
adim dpl,01h
sbi dpl,0fh
bnz clr_lcd
cyc_bs:
ldi dpl,0h
ldi dpm,0
ldi dph,06
bs_lcd:
ldi inx,1111b
adim dpl,01h
sbi dpl,0fh
bnz bs_lcd
call delay_250ms
sbim cyc,01
bnz cyc_bs
ldi setting,0000b
;--------------------------------
ldi dpl,0
ldi dpm,0
ldi dph,06
clr_lcd1:
ldi inx,0
adim dpl,01h
sbi dpl,0fh
bnz clr_lcd1
;--------------------------------
;--------------------------------
ldi tmod,0111b ;011b
ldi tl0,0eh ;06h-100ms
ldi th0,0ah ;0eh-100ms
ldi irq,0
ldi ie,0000b
;--------------------------------
ldi flag,1000b
ldi temp,0
;--------------------------------
main:
call display
call keyscan
lda kbz
ba0 time0_startwork
ba1 time0_stopwork
ba2 r_start
jmp main
;--------------------------------
time0_startwork:
ldi ie,0100b
ldi irq,0
jmp main
;--------------------------------
time0_stopwork:
ldi ie,0
ldi irq,0
jmp main
;--------------------------------
delay:
ldi ct4,09h
LDI ct5,0eh;
SBIM ct5,01h ;
BC $-1
sbim ct4,01h ;
bc $-4
RTNI
delay_250ms:
ldi ct1,0bh ;
ldi ct2,09h ;
ldi ct3,06h ;
sbim ct3,01 ;
bc $-1
sbim ct2,01 ;
bc $-4
sbim ct1,01 ;
bc $-7
rtni
;----------------------------
;---------------------------
;part lcd display
;---------------------------
display:
dasplay1:
lda sec_1,0
call 070fh
lda lcdh
sta 30ah
lda lcdl
sta 309h
dasplay2:
lda flag
bnz $+2
bc clr_lcd_zero
lda sec_2,0
call 070fh
lda lcdh
sta 308h
lda lcdl
sta 307h
lda flag
andim flag,1000b
orm 307h
dasplay3:
lda min_1,0
call 070fh
lda lcdh
sta 306h
lda lcdl
sta 305h
dasplay4:
lda min_2,0
baz clr_min_2
lda min_2,0
call 070fh
lda lcdh
sta 304h
lda lcdl
sta 303h
rtni
clr_lcd_zero:
ldi temp,0
sta 305h
sta 306h
sta 307h
sta 308h
rtni
clr_min_2:
ldi temp,0
sta 304h
sta 303h
rtni
lcd0:
ldi lcdh,0fh
ldi lcdl,05
rtni
lcd1:
ldi lcdh,06
ldi lcdl,00
rtni
lcd2:
ldi lcdh,0bh
ldi lcdl,06
rtni
lcd3:
ldi lcdh,0fh
ldi lcdl,02h
rtni
lcd4:
ldi lcdh,06h
ldi lcdl,03h
rtni
lcd5:
ldi lcdh,0dh
ldi lcdl,03h
rtni
lcd6:
ldi lcdh,0Dh
ldi lcdl,07h
rtni
lcd7:
ldi lcdh,07h
ldi lcdl,0h
rtni
lcd8:
ldi lcdh,0fh
ldi lcdl,07h
rtni
lcd9:
ldi lcdh,0fh
ldi lcdl,03h
rtni
org 070fh
tjmp
jmp lcd0
jmp lcd1
jmp lcd2
jmp lcd3
jmp lcd4
jmp lcd5
jmp lcd6
jmp lcd7
jmp lcd8
jmp lcd9
;---------------------------------
rtni
;-----------------------------------------
;part keyscan
;-----------------------------------------
keyscan:
lda pb
sta pb_bak
sbi pb_bak,1111b
baz no_key
jmp key_work
key_work:
call delay_250ms
lda pb
sub pb_bak
bnz no_key
eorim pb_bak,0fh
;--------------------------------
ba2 what_doing
;--------------------------------
; ba0 key_1
; ba1 key_2
; ba2 key_3
;--------------------------------
no_key:
rtni
;--------------------------------
what_doing:
adim bzw,01
sbi bzw,01
baz key_doing_1
sbi bzw,02
baz key_doing_2
sbi bzw,03
baz key_doing_3
sbi bzw,04
baz key_doing_4
sbi bzw,05
baz key_doing_5
sbi bzw,06
baz key_doing_6
;--------------------------------
rtni
;--------------------------------
;--------------------------------
; working mode
;time--cnt--cal--rpm--tcnt--scan
;--------------------------------
;--------------------------------
; time mode
;--------------------------------
key_doing_1:
ldi flag,1000b
ldi temp,0
sta 302h
ldi temp,1000b
sta 302h
rtni
;--------------------------------
; cnt mode
;--------------------------------
key_doing_2:
ldi temp,0
sta flag
sta 302h
shr
ldi temp,0001b
sta 301h
rtni
;--------------------------------
; cal mode
;--------------------------------
key_doing_3:
ldi temp,0
sta 301h
sta flag
ldi temp,0001b
sta 300h
rtni
;--------------------------------
; rpm -odo- mode
;--------------------------------
key_doing_4:
ldi temp,0
sta 300h
sta flag
ldi temp,1000b
sta 30bh
rtni
;--------------------------------
; tcnt mode
;--------------------------------
key_doing_5:
ldi temp,0
sta 30bh
sta flag
ldi temp,0100b
sta 300h
rtni
;--------------------------------
; scan mode
;--------------------------------
key_doing_6:
ldi temp,0
sta bzw
sta flag
sta 300h
ldi temp,0100b
sta 302h
rtni
;--------------------------------
;*****************************
list p=6612
;*****************************
ie equ 00h
irq equ 01h
tmod equ 02h
tmod1 equ 03h
tl0 equ 04h
th0 equ 05h
tl1 equ 06h
th1 equ 07h
pa equ 08h
pb equ 09h
pc equ 0ah
pd equ 0bh
tbr equ 0eh
inx equ 0fh
dpl equ 10h
dpm equ 11h
dph equ 12h
setting equ 13h
ace equ 14h
duty equ 15h
sec_1 equ 20h
sec_2 equ 21h
min_1 equ 22h
min_2 equ 23h
min_3 equ 24h
min4_1 equ 25h
min4_2 equ 26h
min4_3 equ 27h
kbz equ 28h
bzw equ 29h
sbzw equ 2ah
mbzw equ 2bh
s4_bzw equ 2ch
acc_bak equ 2fh
pb_bak equ 30h
ct0 equ 31h
ct1 equ 33h
ct2 equ 34h
ct3 equ 35h
ct4 equ 36h
ct5 equ 37h
cyc equ 3fh
lcdl equ 40h
lcdm equ 41h
lcdh equ 42h
temp equ 43h
flag equ 44h
END