PIC单片机程序设计的基本格式
发布时间:2008/5/27 0:00:00 访问次数:567
title“this is……”;程序标题
;程序说明
list p=16f84,f=1nhx8m
;
include <p16f84.inc>
-config_rc_qsc &_wdt_0ff…
;资源定义和变量定义
status equ 03
fsr equ 04
porta equ 05
portb equ 06
j equ 01f
k equ 01e
;…………………
org 0000 ;
goto main ;跳过中断矢量
org 0004
goto intsrv;子程序入口地址
;……………………………………
main ;从0005h开始放主程序
call initports ;端口初始化
call inittimers;定时器初始化
…
intsrv … ;中断服务程序区
svbrth… ;子程序区
end ;程序结束符
当然,在编写程序时可根据实际情况加以调整。下面是一份实际程序清单,要求将数据88h写入pic16f84单片机内部eeprom的20h单元,而后再从20h单元将其读出。
list p=16f84,f=inhx8m
;……………………………
status equ 03 ;定义寄存器
eedata equ 08
eeadr equ 09
intcon equ 0bh
eecon1 equ 88h
eecon2 equ 89h
;…………………………
rd equ 0 ;定义位
wr equ 1
rp0 equ 5
gie equ 7
;…………………………
org 0
goto wrstart
;……………………………
org 10h
wrstart ;写入操作开始
clrw ;清w,使w=0
bcf status,rp0 ;选bank0
movlw 20h
movwf eeadr ;地址→eeadr
movlw 88h
movwf eedata ;写入数据→
;eedata
bsf status,rp0 ;选bank1
bsf eecon1,2 ;写操作使能允许
bcf intcon,gie ;关闭所有的中断
movlw 0x55
movwf eecon2 ;55h→eecon2
movlw 0xaa
movwf eecon2 ;aah→eecon2
bsf eecon1,wr ;启动写操作
bsf intcon,gie ;恢复开中断
rdstart ;读出操作开始
bcf status,rp0
movlw 20h
movwf eeadr ;地址→eeadr
bsf status,rp0
bsf eecon1,rd ;启动读操作
bcf status,rp0
movf eedata,w ;将eeprom
;数据读入w
end
title“this is……”;程序标题
;程序说明
list p=16f84,f=1nhx8m
;
include <p16f84.inc>
-config_rc_qsc &_wdt_0ff…
;资源定义和变量定义
status equ 03
fsr equ 04
porta equ 05
portb equ 06
j equ 01f
k equ 01e
;…………………
org 0000 ;
goto main ;跳过中断矢量
org 0004
goto intsrv;子程序入口地址
;……………………………………
main ;从0005h开始放主程序
call initports ;端口初始化
call inittimers;定时器初始化
…
intsrv … ;中断服务程序区
svbrth… ;子程序区
end ;程序结束符
当然,在编写程序时可根据实际情况加以调整。下面是一份实际程序清单,要求将数据88h写入pic16f84单片机内部eeprom的20h单元,而后再从20h单元将其读出。
list p=16f84,f=inhx8m
;……………………………
status equ 03 ;定义寄存器
eedata equ 08
eeadr equ 09
intcon equ 0bh
eecon1 equ 88h
eecon2 equ 89h
;…………………………
rd equ 0 ;定义位
wr equ 1
rp0 equ 5
gie equ 7
;…………………………
org 0
goto wrstart
;……………………………
org 10h
wrstart ;写入操作开始
clrw ;清w,使w=0
bcf status,rp0 ;选bank0
movlw 20h
movwf eeadr ;地址→eeadr
movlw 88h
movwf eedata ;写入数据→
;eedata
bsf status,rp0 ;选bank1
bsf eecon1,2 ;写操作使能允许
bcf intcon,gie ;关闭所有的中断
movlw 0x55
movwf eecon2 ;55h→eecon2
movlw 0xaa
movwf eecon2 ;aah→eecon2
bsf eecon1,wr ;启动写操作
bsf intcon,gie ;恢复开中断
rdstart ;读出操作开始
bcf status,rp0
movlw 20h
movwf eeadr ;地址→eeadr
bsf status,rp0
bsf eecon1,rd ;启动读操作
bcf status,rp0
movf eedata,w ;将eeprom
;数据读入w
end
上一篇:PIC 8位单片机的汇编语言
上一篇:PIC系列单片机程序设计基础四