[ บทความ : ตัวอย่างสำหรับ AVR ตอนที่ 15 ] ทดสอบ RS485 ของ ET-AVR V1/2 และ CP-jrAVR

ตัวอย่างซอร์สโค้ดสำหรับติดต่อกับ RS485 ของบอร์ด ET-AVR V1/2 และ CP-jrAVR เป็นดังนี้

;***************************************************************************
;* A P P L I C A T I O N   N O T E   F O R   T H E   A V R   F A M I L Y
;* 
;* Number		:AVR
;* File Name            :"rs485.asm"
;* Title                :rs485 echo
;* Date                 :25/02/43
;* Version              :1.0
;* Support telephone	:712 1120-1 (ETT)
;* Support fax		:3917216 (ETT)
;* Support www          :www.etteam.com,www.ett.co.th
;* Target MCU		:AT90S8535/AT90LS8535
;*
;***************************************************************************
;
.include "2313def.inc"

            .org   $0000 
             rjmp  reset                ;Reset Handle

;****************************************************************************
;*
;* Test/Example Program
;*
;****************************************************************************
.def	    temp  = r19   

RESET:      LDI     temp,low(RAMEND)
            OUT     spl,temp            ;init Stack Pointer Low     

            LDI     temp,high(RAMEND)
            OUT     spl+1,temp          ;init Stack Pointer High

            CLI                         ;clear golbal interrupt
            CBI     UCR,RXCIE           ;clesr rx interrupt
            CBI     UCR,TXCIE           ;clesr tx interrupt
            CBI     UCR,UDRIE           ;clesr data empty interrupt
            CBI     UCR,CHR9            ;send 8 data 

            LDI     R17,51
            OUT     UBRR,r17            ;baud 9600 at 8MHz Xtal 
  
            SBI     UCR,TXEN            ;set pin tx as serial TX 
            SBI     UCR,RXEN            ;set pin rx as serial RX 

            SBI     DDRD,4

            LDI     ZH,high(TEXT_TAB*2)
            LDI     ZL,low(TEXT_TAB*2)
XX:         LPM
            LDI     R16,0X00
            CP      R0,R16
            BREQ    YY 
            MOV     R20,R0
            RCALL   TX232
            ADIW    ZL,1
            RJMP    XX

YY:         RCALL   RX232
            RCALL   TX232 
            RJMP    YY
            
           
TX232:      SBI     PORTD,4
            SBIS    USR,UDRE           ;wait until UDRE = 1
            RJMP    TX232 
            OUT     UDR,R20            ;send data to serial  
            RET 
            
RX232:      CBI     PORTD,4
            SBIS    USR,RXC            ;wait until have data in buffer
            RJMP    RX232
            IN      R20,UDR            ;read data from buffer
            RET

TEXT_TAB:   .DB     0X0C,"CP-JRAVR V1.0",0X0A,0X0D
            .DB     "TEST  RS485 ",0X00



สามารถ download ไฟล์ตัวอย่างของบอร์ด พร้อม assembler ได้เลยครับ


เขียนโดย : ETT
Author : ETT team
e-mail : sales@etteam.com
วันที่ทำการปรับปรุง : ๒๕ พ.ย. ๒๕๔๓