Ответ: вот вам на растерзание
(«Телесистемы»: Конференция «Микроконтроллеры и их применение»)

миниатюрный аудио-видеорекордер mAVR

Отправлено anonimus 01 января 2005 г. 17:45
В ответ на: Если не работает только D7, то будет выводить английские символы до 0х80 и первую строку т.к. вторая строка 0х80. Давай кусок программы в студию. отправлено Sinelogic 01 января 2005 г. 17:10

START
call init_reg
call LCD_Init ; Set up the LCD Module
movlw CLR_DISP ; добавим...
call Send_Cmd
movlw b'00001111' ; Display on, cursor on, blink on
call Send_Cmd
movlw b'00000110' ; Increment cursor (Entry_Set)
call Send_Cmd

w
btfsc fl,0
goto w
call vr
bsf fl,0
goto w
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; ВЫВОД В ПЕРВУЮ СТРОКУ
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
vr
movlw CLR_DISP
call Send_Cmd
movlw LINE1
call Send_Cmd
movlw ' '
call sch_b
movlw 0a1h
call sch_b
movlw 0b1h
call sch_b
movlw 't'
call sch_b
movlw 't'
call sch_b
movlw 't'
call sch_b
movlw 't'
call sch_b
movlw 't'
call sch_b
movlw ' '
call sch_b
movlw ' '
call sch_b
movlw ' '
call sch_b
movlw ' '
call sch_b
movlw ' '
call sch_b
movlw ' '
call sch_b
movlw ' '
call sch_b
movlw ' '
call sch_b
;*****************************************************************
;
;*****************************************************************

sch_b ; вывод символа с проверкой перехода во 2 строку
call schar
return

;
;*******************************************************************
;* The LCD Module Subroutines *
;*******************************************************************
;
;*******************************************************************
;*SendChar - Sends character to LCD *
;*This routine splits the character into the upper and lower *
;*nibbles and sends them to the LCD, upper nibble first. *
;*******************************************************************
;
schar
Send_Char
movwf Char ; Character to be sent is in W
call Wait_Busy ; Wait for LCD to be ready
movlw 0x0f
andwf LCD_DATA,F ; Clear the upper nibble
movf Char,w
andlw 0xF0 ; Get upper nibble
iorwf LCD_DATA,F ; Send data to LCD
bcf LCD_CNTL, R_W ; Set LCD to write
bsf LCD_CNTL, RS ; Set LCD to data mode
bsf LCD_CNTL, E ; toggle E for LCD
bcf LCD_CNTL, E
movlw 0x0f
andwf LCD_DATA,F ; Clear the upper nibble
swapf Char,W
andlw 0xF0 ; Get lower nibble
iorwf LCD_DATA,F ; Send data to LCD
bsf LCD_CNTL, E ; toggle E for LCD
bcf LCD_CNTL, E
return

;*******************************************************************
;* Send_Cmd - Sends command to LCD *
;* This routine splits the command into the upper and lower *
;* nibbles and sends them to the LCD, upper nibble first. *
;*******************************************************************
scmd
Send_Cmd
movwf Char ; Character to be sent is in W
call Wait_Busy ; Wait for LCD to be ready
movlw 0x0f
andwf LCD_DATA,F ; Clear the upper nibble
movf Char,w
andlw 0xF0 ; Get upper nibble
iorwf LCD_DATA,F ; Send data to LCD
bcf LCD_CNTL,R_W ; Set LCD to write
bcf LCD_CNTL,RS ; Set LCD to command mode
bsf LCD_CNTL,E ; toggle E for LCD
bcf LCD_CNTL,E
movlw 0x0f
andwf LCD_DATA,F ; Clear the upper nibble
swapf Char,W
andlw 0xF0 ; Get lower nibble
iorwf LCD_DATA,F ; Send data to LCD
bsf LCD_CNTL,E ; toggle E for LCD
bcf LCD_CNTL,E
return
;
;*******************************************************************
;* This routine checks the busy flag, returns when not busy *
;* Affects: *
;* Temp - Returned with busy/address *
;*******************************************************************
; В оригинале была ошибка! - исправлено
Wait_Busy
bsf STATUS, RP0 ; Select Register page 1
movlw 0xf0 ; Set port to input
iorwf LCD_DATA_TRIS,W ; Only set upper half of port
movwf LCD_DATA_TRIS
bcf STATUS, RP0 ; Select Register page 0
bcf LCD_CNTL, RS ; Set LCD for Command mode
bsf LCD_CNTL, R_W ; Setup to read busy flag

bsf LCD_CNTL, E ; Set E high
movf LCD_DATA, W ; Read upper nibble busy flag, DDRam address
bcf LCD_CNTL, E ; Set E low

andlw 0xF0 ; Mask out lower nibble
movwf Temp

bsf LCD_CNTL, E ; Toggle E to get lower nibble
swapf LCD_DATA, w ; Read lower nibble busy flag, DDRam address
bcf LCD_CNTL, E


andlw 0x0F ; Mask out upper nibble
iorwf Temp,f ; Combine nibbles, RES in Temp !!!!!!!!!!!!!!!
btfsc Temp, 7 ; Check busy flag, high = busy
goto Wait_Busy ; If busy, check again
bcf LCD_CNTL, R_W
bsf STATUS, RP0 ; Select Register page 1
movlw 0x0F
andwf LCD_DATA_TRIS,W
movwf LCD_DATA_TRIS ; Set Port for output
bcf STATUS, RP0 ; Select Register page 0
return
;
del10mks
goto $+1
goto $+1
goto $+1
goto $+1
return
;
; Initilize the LCD Display Module
;
LCD_Init:

bcf LCD_CNTL, E ; Clear all controll lines
bcf LCD_CNTL, RS
bcf LCD_CNTL, R_W

call delay20 ; Wait for 15ms for LCD to get powered up

movlw 0x0f
andwf LCD_DATA,F ; Clear the upper nibble
movlw 0x030 ; Command for 4-bit interface high nibble
iorwf LCD_DATA,F ; Send data to LCD

bsf STATUS, RP0 ; Select Register page 1
movlw 0x0F
andwf LCD_DATA_TRIS,W
movwf LCD_DATA_TRIS ; Set Port for output
BCF STATUS, RP0 ; Select Register page 0

bsf LCD_CNTL, E ; Clock the initalize command to LCD module
bcf LCD_CNTL, E

call delay5 ; Delay for at least 4.1ms before continuing

bsf LCD_CNTL, E ; Clock the initalize command to LCD module
bcf LCD_CNTL, E


call d100mks ; delay for at least 100usec before continuing

bsf LCD_CNTL, E ; Clock the initalize command to LCD module
bcf LCD_CNTL, E

call Wait_Busy ; From here on, the Busy Bit will be valid.

movlw 0x0f
andwf LCD_DATA,F ; Clear the upper nibble
movlw 0x020 ; Command for 4-bit interface high nibble (Really an 8bit command but
; lower 4 bits are don't care at this point)
iorwf LCD_DATA,F ; Send data to LCD

bsf LCD_CNTL, E ; Clock the initalize command to LCD module
bcf LCD_CNTL, E

movlw FUNCTION_SET ; Send the function set command 4-bit I/F, Font, Number of lines
call Send_Cmd ; Can now use the Send_Cmd routine since Busy Bit Valid and in 4bit mode.
; LCD Module is now initalized
return

init_reg
bsf STATUS,RP0 ; страница 1
movlw b'00000000' ; поpт В7...В0 - вывод
movwf TRISB
movlw b'11111100' ; A4,A3 - ввод, A2,A1,A0 - вывод
movwf TRISC
bcf STATUS,RP0 ; страница 0
; уст нач знач пеpеменных вpемени


Составить ответ  |||  Конференция  |||  Архив

Ответы



Перейти к списку ответов  |||  Конференция  |||  Архив  |||  Главная страница  |||  Содержание  |||  Без кадра

E-mail: info@telesys.ru