用VC實(shí)現(xiàn)PC機(jī)與單片機(jī)的通信
*==========Registers===========
SCCR1 equ $0013
b_ENSCI equ 6
SCCR2 equ $0014
b_TE equ 3
b_RE equ 2
BAUD equ $0019
SCS1 equ $0016
SCS2 equ $0017
SCDR equ $0018
CONFIG2 equ $001e
CONFIG1 equ $001f
PCTL equ $0036
b_PLLON equ 5
b_BCS equ 4
PBWC equ $0037
b_AUTO equ 7
PMSH equ $0038
PMSL equ $0039
PMRS equ $003a
*==========Initial Codes========
ORG $8000
RESET_INIT:
SEI
LDHX #$023F
TXS
LDA #$01
STA CONFIG2
LDA #$3D
STA CONFIG1
*========== Initial CGMC=========
CLR PCTL
MOV #$01,PCTL
MOV #$01,PMSH
MOV #$2C,PMSL
MOV #$80,PMRS
BSET b_PLLON,PCTL ;32.768khz --2.4576Mhz
BSET b_AUTO,PBWC
BSET b_BCS,PCTL
*========= Initial SCI==========*
LDA #$02
STA BAUD ;9600baud
BSET b_ENSCI,SCCR1 ;ENABLE SCI
MOV #$0C,SCCR2 ;ENABLE TRANSMITTER AND RECEIVER
*==========Main program========*
START:CLI
JSR GETDATA
JSR SENDATA
JMP START
GETDATA:BRCLR 5,SCS1,GETDATA
LDA SCDR
RTS
SENDATA:BRCLR 7,SCS1,SENDATA
STA SCDR
RTS
*===========Vector=============*
ORG $FFFE
DW RESET_INIT本文引用地址:http://butianyuan.cn/article/171851.htm
若要實(shí)現(xiàn)一臺(tái)微機(jī)(主機(jī))與多臺(tái)GP32通信,可用SCI接收器喚醒功能(空閑線或地址位)。主機(jī)與從機(jī)通信時(shí),發(fā)送信息的開(kāi)頭一般為從機(jī)地址,各從機(jī)接收信息開(kāi)頭的地址,如發(fā)現(xiàn)地址與自己的地址相同,則準(zhǔn)備接收后面的數(shù)據(jù),負(fù)責(zé)不予理睬。至此我們用Visual C++ 6.0實(shí)現(xiàn)了微機(jī)與微機(jī)以及微機(jī)與單片機(jī)之間的串行通信,通過(guò)更復(fù)雜的通信協(xié)議,完全可滿足工業(yè)測(cè)控系統(tǒng)中的一般數(shù)據(jù)通信要求。
參考文獻(xiàn):
[1]劉慧根等. MC68HC08原理及其嵌入是應(yīng)用. 清華大學(xué)出版社,2001.
[2]劉瑜. Windows環(huán)境下串行通信程序設(shè)計(jì). 計(jì)算機(jī)應(yīng)用與研究,1999.
評(píng)論