共2条
1/1 1 跳转至页
8515,HD44780,ASM 8515和HD44780字符液晶接口的ASM代码
问
;***************************************************************
;Program LCD.ASM
;This Program shows how a LCD with 16 char/ 1 line
;is used with a atmel 8515 and a HD44780 lcd controller
;The crystal is set to 4 MHz
;***************************************************************
.include "8515def.inc"
;Definitions
.equ E = PD0 ;E an Pin PD0
.equ RW = PD1 ;RW an Pin PD1
.equ RS = PD2 ;RS an Pin PD2
.equ BF = PB7 ;Busy flag
;LCD inits
.equ clear_LCD = 0b00000001 ;CLEAR DISPLAY
.equ home_LCD = 0b00000010 ;return home
.equ set_LCD = 0b00111000 ;8 bits,2 line, 5x7 dots
.equ LCD_on = 0b00001110 ;LCD on
.equ entry_mode = 0b00000110 ;set cursor
;Variable definition
.def chr = r0
.def buffer = r16 ;RX/TX Data from LCD
.def counter = r17
.def temp = r18
.def temp2 = r19
.def temp3 = r20
.CSEG
.ORG 0x00 ; Program starts at adress 0x00
rjmp main
;**************************************************************
; Subroutine init
; Init PORTD
;**************************************************************
init: ldi temp,0b11111111 ;PORTD is an output
out DDRD,temp
cbi PORTD,E ;E init
cbi PORTD,RS
cbi PORTD,RW
ret
;***************************************************************
; Subroutine busy_flag
; Test the LCD for sending another instruction
;***************************************************************
busy_flag: ldi temp,0b00000000 ;PORTB is an input
out DDRB,temp
cbi PORTD,RS ;send test
sbi PORTD,RW ;Set LCD in read-mode
sbi PORTD,E ;control LCD
nop
nop
sbic PINB,BF ;LCD busy?
rjmp busy_flag ;no, again
cbi PORTD,E ;disable LCD
ret ;LCD not busy
;***************************************************************
; Subroutine write_data
; Buffer is the data to be sent
;***************************************************************
write_data: rcall busy_flag ;LCD busy?
ldi temp,0b11111111 ;PORTB is an output
out DDRB,temp
sbi PORTD,RS ;Send Data
cbi PORTD,RW ;LCD in write-mode
sbi PORTD,E
out PORTB,buffer ;Send buffer Data
cbi PORTD,E ;disable LCD
ret
;***************************************************************
; Subroutine write_instr
; Sends the instruction for LCD-controller
;***************************************************************
write_instr: rcall busy_flag
ldi temp,0b11111111
out DDRB,temp
cbi PORTD,RS
cbi PORTD,RW
sbi PORTD,E
out PORTB,buffer
cbi PORTD,E
ret
;***************************************************************
; Main
; Text from table is shifted to the right
; **************************************************************
main:
ldi temp,low(RAMEND) ;Initialize stackpointer for parts with SW stack
out SPL,temp
ldi temp,high(RAMEND) ; Commented out since 1200 does not have SRAM
out SPH,temp
rcall init
ldi buffer,set_LCD ;set LCD Function
rcall write_instr
ldi buffer,LCD_on ;LCD on
rcall write_instr
ldi buffer,clear_LCD ;Clear LCD
rcall write_instr
ldi buffer,entry_mode ;Entry mode
rcall write_instr
ldi buffer,0b00000000 ;LCD-Start adress
rcall write_instr
ldi counter,$0F
ldi ZL,LOW(Tabel1*2)
ldi ZH,HIGH(Tabel1*2)
loop_msg1: lpm
mov buffer,chr
rcall write_data
adiw ZL,1
dec counter
brne loop_msg1
ldi buffer,0b11000000
rcall write_instr
ldi counter,$0F
ldi ZL,LOW(Tabel2*2)
ldi ZH,HIGH(Tabel2*2)
loop_msg2: lpm
mov buffer,chr
rcall write_data
adiw ZL,1
no_carry2: dec counter
brne loop_msg2
loop:
ldi temp,0b11111111
out DDRC,temp
ldi buffer,$FF
out PORTC,buffer
ldi buffer,0b00011100
rcall write_instr
rcall delay
rjmp loop
;Tabel1: .DB "123456789abcdef"
Tabel1: .DB "Robot Atmel" ;$00/0F
;Tabel1: .DB "123456789abcdef"
Tabel2: .DB "Fever 1999"
DELAY:
ldi temp,$FF
ldi temp2,$FF
ldi temp3,$09
LOOP_delay:
dec temp
brne LOOP_delay
dec temp2
brne LOOP_delay
dec temp3
brne LOOP_delay
ret
答 1: 好!
;Program LCD.ASM
;This Program shows how a LCD with 16 char/ 1 line
;is used with a atmel 8515 and a HD44780 lcd controller
;The crystal is set to 4 MHz
;***************************************************************
.include "8515def.inc"
;Definitions
.equ E = PD0 ;E an Pin PD0
.equ RW = PD1 ;RW an Pin PD1
.equ RS = PD2 ;RS an Pin PD2
.equ BF = PB7 ;Busy flag
;LCD inits
.equ clear_LCD = 0b00000001 ;CLEAR DISPLAY
.equ home_LCD = 0b00000010 ;return home
.equ set_LCD = 0b00111000 ;8 bits,2 line, 5x7 dots
.equ LCD_on = 0b00001110 ;LCD on
.equ entry_mode = 0b00000110 ;set cursor
;Variable definition
.def chr = r0
.def buffer = r16 ;RX/TX Data from LCD
.def counter = r17
.def temp = r18
.def temp2 = r19
.def temp3 = r20
.CSEG
.ORG 0x00 ; Program starts at adress 0x00
rjmp main
;**************************************************************
; Subroutine init
; Init PORTD
;**************************************************************
init: ldi temp,0b11111111 ;PORTD is an output
out DDRD,temp
cbi PORTD,E ;E init
cbi PORTD,RS
cbi PORTD,RW
ret
;***************************************************************
; Subroutine busy_flag
; Test the LCD for sending another instruction
;***************************************************************
busy_flag: ldi temp,0b00000000 ;PORTB is an input
out DDRB,temp
cbi PORTD,RS ;send test
sbi PORTD,RW ;Set LCD in read-mode
sbi PORTD,E ;control LCD
nop
nop
sbic PINB,BF ;LCD busy?
rjmp busy_flag ;no, again
cbi PORTD,E ;disable LCD
ret ;LCD not busy
;***************************************************************
; Subroutine write_data
; Buffer is the data to be sent
;***************************************************************
write_data: rcall busy_flag ;LCD busy?
ldi temp,0b11111111 ;PORTB is an output
out DDRB,temp
sbi PORTD,RS ;Send Data
cbi PORTD,RW ;LCD in write-mode
sbi PORTD,E
out PORTB,buffer ;Send buffer Data
cbi PORTD,E ;disable LCD
ret
;***************************************************************
; Subroutine write_instr
; Sends the instruction for LCD-controller
;***************************************************************
write_instr: rcall busy_flag
ldi temp,0b11111111
out DDRB,temp
cbi PORTD,RS
cbi PORTD,RW
sbi PORTD,E
out PORTB,buffer
cbi PORTD,E
ret
;***************************************************************
; Main
; Text from table is shifted to the right
; **************************************************************
main:
ldi temp,low(RAMEND) ;Initialize stackpointer for parts with SW stack
out SPL,temp
ldi temp,high(RAMEND) ; Commented out since 1200 does not have SRAM
out SPH,temp
rcall init
ldi buffer,set_LCD ;set LCD Function
rcall write_instr
ldi buffer,LCD_on ;LCD on
rcall write_instr
ldi buffer,clear_LCD ;Clear LCD
rcall write_instr
ldi buffer,entry_mode ;Entry mode
rcall write_instr
ldi buffer,0b00000000 ;LCD-Start adress
rcall write_instr
ldi counter,$0F
ldi ZL,LOW(Tabel1*2)
ldi ZH,HIGH(Tabel1*2)
loop_msg1: lpm
mov buffer,chr
rcall write_data
adiw ZL,1
dec counter
brne loop_msg1
ldi buffer,0b11000000
rcall write_instr
ldi counter,$0F
ldi ZL,LOW(Tabel2*2)
ldi ZH,HIGH(Tabel2*2)
loop_msg2: lpm
mov buffer,chr
rcall write_data
adiw ZL,1
no_carry2: dec counter
brne loop_msg2
loop:
ldi temp,0b11111111
out DDRC,temp
ldi buffer,$FF
out PORTC,buffer
ldi buffer,0b00011100
rcall write_instr
rcall delay
rjmp loop
;Tabel1: .DB "123456789abcdef"
Tabel1: .DB "Robot Atmel" ;$00/0F
;Tabel1: .DB "123456789abcdef"
Tabel2: .DB "Fever 1999"
DELAY:
ldi temp,$FF
ldi temp2,$FF
ldi temp3,$09
LOOP_delay:
dec temp
brne LOOP_delay
dec temp2
brne LOOP_delay
dec temp3
brne LOOP_delay
ret
答 1: 好!
共2条
1/1 1 跳转至页
回复
| 有奖活动 | |
|---|---|
| 2026年“我要开发板活动”第三季,开始了! | |
| 硬核工程师专属补给计划——填盲盒 | |
| “我踩过的那些坑”主题活动——第002期 | |
| 【EEPW电子工程师创研计划】技术变现通道已开启~ | |
| 发原创文章 【每月瓜分千元赏金 凭实力攒钱买好礼~】 | |
| 【EEPW在线】E起听工程师的声音! | |
| 高校联络员开始招募啦!有惊喜!! | |
| 【工程师专属福利】每天30秒,积分轻松拿!EEPW宠粉打卡计划启动! | |
我要赚赏金打赏帖 |
|
|---|---|
| 以启明云端ESP32P4开发板实现TF卡读写功能被打赏¥28元 | |
| 【分享开发笔记,赚取电动螺丝刀】树莓派5串口UART0配置被打赏¥25元 | |
| 【STM32F103ZET6】17:分享在Rtos项目中断管理的使用经验被打赏¥23元 | |
| 【STM32F103ZET6】16:分享在中断中恢复串口任务,遇到的问题被打赏¥31元 | |
| 在FireBeetle2ESP32-C5上实现温度大气压检测及显示被打赏¥21元 | |
| 【分享开发笔记,赚取电动螺丝刀】SAME51双串口收发配置被打赏¥27元 | |
| Chaos-nano操作系统在手持式VOC检测设备上的应用被打赏¥37元 | |
| 【分享开发笔记,赚取电动螺丝刀】关于在导入第三方库lib时,wchart类型冲突的原因及解决方案被打赏¥30元 | |
| 在FireBeetle2ESP32-C5上实现温湿度检测和显示被打赏¥20元 | |
| 在FireBeetle2ESP32-C5上实现光照强度检测及显示被打赏¥21元 | |
我要赚赏金
