[ บทความ : ตัวอย่างสำหรับ AVR ตอนที่ 16 ] ทดสอบติดต่อกับบอร์ดแสดงผล SDP8 ของ CP-jrAVR |
ตัวอย่างซอร์สโค้ดสำหรับติดต่อกับบอร์ดแสดงผลรุ่น ET-SDP8 ของอีทีที กับบอร์ด CP-jrAVR เป็นดังนี้
;*************************************************************************** ;* APPLICATION NOTE FOR THE CP-JRAVR * ;* * ;* Control Board :CP-JRAVR * ;* File Name :"SDP8.ASM" * ;* Title :7 SEGMENT DISPLA * ;* Date :10/9/42 * ;* 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_MAX = PORTB .EQU DDR_MAX = DDRB .EQU BIT_LOAD = 5 .EQU BIT_DIN = 6 .EQU BIT_CLK = 7 .DEF TEMP = R19 .DEF TEMP1 = R20 .DEF TEMP2 = R21 .DEF TEMP3 = R22 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 RCALL DELAY ;delay for start SBI DDR_MAX,BIT_LOAD SBI DDR_MAX,BIT_DIN SBI DDR_MAX,BIT_CLK SBI PORT_MAX,BIT_LOAD SBI PORT_MAX,BIT_DIN CBI PORT_MAX,BIT_CLK RCALL INIT_7219 LDI TEMP3,0X01 LDI TEMP2,0X00 RCALL MAX7219 LDI TEMP3,0X02 LDI TEMP2,0X01 RCALL MAX7219 LDI TEMP3,0X03 LDI TEMP2,0X02 RCALL MAX7219 LDI TEMP3,0X04 LDI TEMP2,0X03 RCALL MAX7219 LDI TEMP3,0X05 LDI TEMP2,0X04 RCALL MAX7219 LDI TEMP3,0X06 LDI TEMP2,0X05 RCALL MAX7219 LDI TEMP3,0X07 LDI TEMP2,0X06 RCALL MAX7219 LDI TEMP3,0X08 LDI TEMP2,0X07 RCALL MAX7219 WAIT: RJMP WAIT ;*************************************************** ;* initial MAX7219 * ;*************************************************** INIT_7219: LDI TEMP3,0X09 ;decode address LDI TEMP2,0XFF ;decode digit 7-0 RCALL MAX7219 LDI TEMP3,0X0A LDI TEMP2,0X0F RCALL MAX7219 LDI TEMP3,0X0B ;scan address LDI TEMP2,0X07 ;scan 8 digit RCALL MAX7219 LDI TEMP3,0X0C ;short down mode LDI TEMP2,0X01 ;normal operate RCALL MAX7219 LDI TEMP3,0X0F LDI TEMP2,0X00 RCALL MAX7219 RET ;*************************************************** ;* ;*************************************************** MAX7219: CBI PORT_MAX,BIT_LOAD LDI TEMP1,16 SDP1: CBI PORT_MAX,BIT_DIN LSL TEMP2 ROL TEMP3 BRCC SDP2 SBI PORT_MAX,BIT_DIN SDP2: CBI PORT_MAX,BIT_CLK SBI PORT_MAX,BIT_CLK DEC TEMP1 BRNE SDP1 SBI PORT_MAX,BIT_LOAD 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สามารถ download ไฟล์ตัวอย่างของบอร์ด พร้อม assembler ได้เลยครับ