石家庄论坛's Archiver

lyq_4652 发表于 2008-8-2 13:57

科威PLC芯片组开发实例(五)

[font=宋体]这一讲里面将会讲解科威[/font][font=Times New Roman]PLC[/font][font=宋体]芯片组开发用户驱动的具体格式。笔者始终认为,学编程,从看代码开始是捷径!所以,我们在[/font][font=Times New Roman]PCLDR.ASM[/font][font=宋体]内添加以下一段代码。[/font]
[font=Times New Roman] [/font]
[font=Times New Roman]$INCLUDE(C8051F040.INC)
; Register definition file.
-------------------1
[/font]
[font=Times New Roman]$INCLUDE(easycore.INC)

; easycore [/font][font=宋体]符号定义[/font][font=Times New Roman]------------------------2

[/font]
[font=Times New Roman]$INCLUDE(EASYCORE.LIB)
; easycore [/font][font=宋体]子程序[/font][font=Times New Roman]---------------------------3

[/font]
[font=Times New Roman]$INCLUDE(user_data.INC)

; [/font][font=宋体]用户程序变量定义[/font][font=Times New Roman]------------------------4

[/font]
[font=Times New Roman];================[/font][font=宋体]中断向量重定向地址[/font][font=Times New Roman]=======================[/font]
[font=Times New Roman]

ORG

0E000H


[/font]
[font=Times New Roman]

ORG

0E003H


;external interrupt0 vecter (INT0)------5[/font]
[font=Times New Roman]

ORG

0E013H


;external interrupt1(INT1)---------------6[/font]
[font=Times New Roman]

ORG

0E033H

;Serial Peripheral Interface(SPI)--------7[/font]
[font=Times New Roman]

ORG

0E03BH


;SMBus interface-------------------------8[/font]
[font=Times New Roman]

ORG

0E043H

;ADC0 Window Comparator;----------9[/font]
[font=Times New Roman]

ORG

0E04BH


;Programmable Counter Array--------10[/font]
[font=Times New Roman]

ORG

0E053H


;Comparator 0---------------------------11[/font]
[font=Times New Roman]

ORG

0E05BH


;Comparator 1---------------------------12[/font]
[font=Times New Roman]

ORG

0E063H


;Comparator 2
--------------------------13[/font]
[font=Times New Roman]

ORG

0E07BH

;ADC0 end of Conversion-------------14[/font]
[font=Times New Roman]

ORG

0E083H

;Timer
4-------------------------------15[/font]
[font=Times New Roman]

ORG

0E08BH

;ADC2 end of Conversion-------------16[/font]
[font=Times New Roman]

ORG

0E093H

;ADC2 Window Comparator-----------17[/font]
[font=Times New Roman];===============[/font][font=宋体]用户应用程序调用入口[/font][font=Times New Roman]====================[/font]
[font=Times New Roman]

ORG

0E0A0H


;[/font][font=宋体]用户端口初始化[/font]
[font=Times New Roman]

LJMP

INIT_CONFIG
;----------------------- --------------------18
[/font]
[font=Times New Roman]

ORG

0E0A3H

;[/font][font=宋体]用户上电初始化[/font]
[font=Times New Roman]

LJMP

INIT_START

;----------------------- --------------------19
[/font]
[font=Times New Roman]

ORG

0E0A6H

;[/font][font=宋体]用户设置初始化[/font]
[font=Times New Roman]

LJMP

INIT_SET

;----------------------- --------------------20
[/font]
[font=Times New Roman]

ORG

0E0A9H

;[/font][font=宋体]用户运行初始化[/font]
[font=Times New Roman]

LJMP

INIT_RUN

;----------------------- --------------------21[/font]
[font=Times New Roman]

ORG

0E0ACH

;[/font][font=宋体]演算周期扫描[/font]
[font=Times New Roman]

LJMP

SCAN


;----------------------- --------------------22[/font]
[font=Times New Roman]

ORG

0E0B0H

;[/font][font=宋体]指令周期扫描[/font]
[font=Times New Roman]

LJMP

STEP


;----------------------- --------------------23[/font]
[font=Times New Roman]

ORG

0E0B3H


;2.5MS[/font][font=宋体]周期扫描[/font][font=Times New Roman]

[/font]
[font=Times New Roman]

LJMP

TMS


;----------------------- --------------------24[/font]
[font=Times New Roman]

[/font]
[font=Times New Roman]

ORG

0E100H


;----------------------- --------------------25[/font]
[font=Times New Roman] [/font]
[font=Times New Roman] [/font]
[font=Times New Roman]INIT_CONFIG:[/font]
[font=Times New Roman]

RET[/font]
[font=Times New Roman] [/font]
[font=Times New Roman]INIT_START:[/font]
[font=Times New Roman]

RET[/font]
[font=Times New Roman] [/font]
[font=Times New Roman]INIT_SET:[/font]
[font=Times New Roman]

RET[/font]
[font=Times New Roman] [/font]
[font=Times New Roman]INIT_RUN:[/font]
[font=Times New Roman]

RET[/font]
[font=Times New Roman] [/font]
[font=Times New Roman]STEP:[/font]
[font=Times New Roman]

RET[/font]
[font=Times New Roman] [/font]
[font=Times New Roman]TMS:[/font]
[font=Times New Roman]

RET[/font]
[font=Times New Roman] [/font]
[font=Times New Roman]SCAN:[/font]
[font=Times New Roman]

RET[/font]
[font=Times New Roman] [/font]
[font=Times New Roman]END

;-------------------------------------------------------------26[/font]
[font=Times New Roman] [/font]
[font=宋体]然后点击编译,如无意外,[/font][font=Times New Roman]KEIL[/font][font=宋体]将会编译成功并生成“[/font][font=Times New Roman]PLCDR.HEX[/font][font=宋体]”文件,该文件可以在项目路径下找到。[/font]
[font=Times New Roman] [/font]
[font=宋体]至此,你的第一个驱动程序已经编写完成。只不过这是一个简单的驱动程序,简单到什么也没有的驱动程序。嘿嘿,如果把这段[/font][font=Times New Roman]HEX[/font][font=宋体]代码下到你的[/font][font=Times New Roman]PLC[/font][font=宋体]内,[/font][font=Times New Roman]PLC[/font][font=宋体]的[/font][font=Times New Roman]IO[/font][font=宋体]口可能会乱跳的哦[/font][font=Times New Roman]~[/font][font=宋体]不过,梯形图的解释倒是独立于驱动之外的,加载了一个什么也没有的驱动,[/font][font=Times New Roman]PLC[/font][font=宋体]芯片组也是可以正常运行梯形图的。[/font]
[font=Times New Roman] [/font]
[font=宋体]在下一讲里,笔者将会逐句给你分析以上程序的每一条语句哦[/font][font=Times New Roman]~[/font][font=宋体]其实从那些简短的注释里,相信不少读者已经看出了些许端倪了。[/font]
[font=Times New Roman] [/font]
[font=宋体]本帖首发中国工控网科威[/font][font=Times New Roman]PLC[/font][font=宋体]论坛,转载请声明![/font]
[font=Times New Roman] [/font]

页: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.