[ บทความ : ตัวอย่างสำหรับ AVR ตอนที่ 13 ] ทดสอบ A/D Convertor ของ CP-jrAVR |
ตัวอย่างซอร์สโค้ดสำหรับติดต่อกับ A/D Convertor เบอร์ LTC1298 ของบอร์ด CP-jrAVR เป็นดังนี้
;*************************************************************************** ;* APPLICATION NOTE FOR THE CP-JRAVR * ;* * ;* Control Board :CP-JRAVR * ;* File Name :"LTC1298.ASM" * ;* Title :SERIAL ADC(LTC1298) TO RS232 * ;* :9600,N,8,1 * ;* 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 :AT90S2313/AT90LS2313 * ;*************************************************************************** .include "2313def.inc" .ORG $0000 RJMP RESET_VEC ;Reset Handle .EQU PORT_ADC = PORTD .EQU DDR_ADC = DDRD .EQU PIN_ADC = PIND .EQU BIT_CLK = 5 .EQU BIT_IO = 4 .EQU BIT_EN = 3 .DEF TEMP = R19 .DEF TEMP1 = R20 .DEF TEMP2 = R21 .DEF TEMP3 = R22 .DEF TEMP4 = R23 RESET_VEC: 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 RCALL DELAY ;delay for start SBI DDR_ADC,BIT_IO SBI DDR_ADC,BIT_EN SBI DDR_ADC,BIT_CLK SBI PORT_ADC,BIT_EN SBI PORT_ADC,BIT_CLK SBI PORT_ADC,BIT_IO LDI ZH,high(TEXT_TAB*2) LDI ZL,low(TEXT_TAB*2) XX: LPM LDI R16,0X00 CP R0,R16 BREQ YY MOV TEMP,R0 RCALL TX232 ADIW ZL,1 RJMP XX YY: LDI TEMP4,0X40 RCALL LTC1298 ANDI TEMP3,0X0F MOV TEMP,TEMP3 RCALL HEXASC RCALL TX232 PUSH TEMP2 SWAP TEMP2 ANDI TEMP2,0X0F MOV TEMP,TEMP2 RCALL HEXASC RCALL TX232 POP TEMP2 ANDI TEMP2,0X0F MOV TEMP,TEMP2 RCALL HEXASC RCALL TX232 LDI TEMP,0X20 RCALL TX232 RCALL TX232 RCALL TX232 LDI TEMP4,0X60 RCALL LTC1298 ANDI TEMP3,0X0F MOV TEMP,TEMP3 RCALL HEXASC RCALL TX232 PUSH TEMP2 SWAP TEMP2 ANDI TEMP2,0X0F MOV TEMP,TEMP2 RCALL HEXASC RCALL TX232 POP TEMP2 ANDI TEMP2,0X0F MOV TEMP,TEMP2 RCALL HEXASC RCALL TX232 LDI TEMP,0X0D RCALL TX232 RJMP YY ;****************************************************** ;* READ ADC(LTC1298) MSB FIRST,SIGNED END MODE * ;* DATA OUT: TEMP3:TEMP2 * ;****************************************************** LTC1298: CLR TEMP2 CLR TEMP3 LDI TEMP1,0X04 LDI TEMP,0X90 OR TEMP,TEMP4 CBI PORT_ADC,BIT_EN CONTB: SBI PORT_ADC,BIT_IO LSL TEMP BRCS CONTB1 CBI PORT_ADC,BIT_IO CONTB1: CBI PORT_ADC,BIT_CLK SBI PORT_ADC,BIT_CLK DEC TEMP1 BRNE CONTB CBI DDR_ADC,BIT_IO SBI PORT_ADC,BIT_IO CBI PORT_ADC,BIT_CLK SBI PORT_ADC,BIT_CLK LDI TEMP1,12 DATA: CBI PORT_ADC,BIT_CLK CLC SBIC PIN_ADC,BIT_IO SEC SBI PORT_ADC,BIT_CLK ROL TEMP2 ROL TEMP3 DEC TEMP1 BRNE DATA SBI PORT_ADC,BIT_EN SBI DDR_ADC,BIT_IO RET ;*************************************************** ;* DELAY TIME FOR START * ;*************************************************** DELAY: PUSH R26 PUSH R27 LDI R27,0XFF DEL2: LDI R26,0XFF DEL1: DEC R26 BRNE DEL1 DEC R27 BRNE DEL2 POP R27 POP R26 RET HEXASC: LDI TEMP1,0X30 CPI TEMP,0X0A BRCS HEXASC1 LDI TEMP1,0X36 HEXASC1: ADD TEMP,TEMP1 RET TX232: SBIS USR,UDRE ;wait until UDRE = 1 RJMP TX232 OUT UDR,TEMP ;send data to serial RET TEXT_TAB: .DB 0X0C,"CP-JRAVR V1.0",0X0A,0X0D .DB "TEST ADC(LTC1298)",0X0A,0X0D,0X00สามารถ download ไฟล์ตัวอย่างของบอร์ด พร้อม assembler ได้เลยครับ