OI FABIO,
SEGUE ABAIXO TODO O CÓDIGO:
A OUTRA COISA ESTOU A PRINCIPIO TENTANDO SIMULAR NO PROTEUS , MAS NO PROTEUS NÃO TEM ESTE CI, E O UQ EU FAÇO É COLOCAR UMA CHAVINHA DE ACIONAMENTO MOMENTANEA PARA ALTERNAR ENTRE VCC E TERRA, AS VEZES APARECE O TEXTO DO INICIO DE FUNCIONAMENTO DO PROJETO NO DISPLAY E AS VEZES NÃO.
**********************************************
;Main program voor de dci_bus
;kan momenteel het volgende
;een 4 bits lcd aansturing
;bij het opstarten verschijnt er op het display
; "DCI-BUS INIT OK"
; "waiting for data..
;Daarna kan er een tekst van 20 char lang naar het display verzonden
; worden via de seriële poort.
; dit werkte uitstekend op 30-9-2001
;
;pin for 4 bit connections:
;
;LCD -> AT90S8515
;DB4 -> PD4
;DB5 -> PD5
;DB6 -> PD6
;DB7 -> PD7
;E -> PD2
;RS -> PD3
;R/W -> GROUND = write
;signals PC and station
;=========================================================================
;PC signals
; ____ __________________
;Send data__________| |__| |____________________________
;
;
; __________ __________________________
;RTS |________________________________|
;
;
;
;Station signals
;
; ___________
;Send data___________________________________________| |__________
;
;
; ________________________________________ ________
;PORTB 3 | |_____________|
;
;
;**********************************************
.device AT90S8915
.include "8515def.inc" ;.include "c:\avrtools\appnotes\8515def.inc"
.def text = r0 ;for rs-port
.def count1 = r10 ;for wait instructions
.def count2 = r11 ;for wait instructions
.def count3 = r12 ;for wait instructions
.def count4 = r13 ;for wait instructions
.def ax = r16
.def bx = r17
.def cx = r18
.def dx= r19
.def lcd_temp = r20 ;;for lcd display
.def col = r21 ;collum display
.def x_counter = r22 ;counter for display
.def ex = r23
.def fx = r24
.def hx = r25
;ram ram ram ram ram ram ram ram ram ram ram
;static var
.equ e = 2 ;enable voor display
.equ rs = 3 ;register selectie voor display
.equ addr=$100 ;voor bijhouden adres
.equ jumpers=$101
;sram van $60....025F
.equ P_String =$60 ;start address of SRAM array #1
;.equ P_String2 =$74 ;start address of SRAM array #2
.cseg
.org $000
rjmp reset ;reset handle
;**************************
;begin to init the hardware
;**************************
reset:
;init stackpointer for 8515
ldi ax,0x005f
out spl,ax ;set lowbyte for sp
ldi ax,high(ramend)
out sph,ax ;set highbyte for sp
;portd 2...7 outputs
ldi ax,0b11111100
out ddrd,ax
ldi ax,0b00000000
out portd,ax
;portc all inputs
ldi ax,0b00000000
out ddrc,ax
;portb 0...4 outputs 5 input 6..7 outputs
ldi ax,0b11011111 ;00011111
out ddrb,ax
ldi ax,0b11111111 ;0b11011111 pin5 pull-up patch 18-3-2002
out portb,ax
;porta all outputs
ldi ax,0b11111111
out ddra,ax ;porta all output
ldi ax,0b11111111
out porta,ax
;init uart portd pin0 en pin1
ldi ax,1 ;12 of 11=19200 boud 1 =115200
out ubrr,ax ;load baudrate
; sbi ucr,chr9 ;9 char long
rjmp init_lcd ;init lcd display
;*****************
;delay instructions
;*****************
w_1ms:
ldi ax,0
mov count1,ax
mov count2,ax
ldi ax,10;16 ;16 = ca. 1ms
mov count3,ax
ldi ax,255
mov count4,ax
rjmp zaehl
w_5ms:
ldi ax,0
mov count1,ax
mov count2,ax
ldi ax,60;80 ;80 = ca. 5ms
mov count3,ax
ldi ax,255
mov count4,ax
rjmp zaehl
w_16ms:
ldi ax,0
mov count1,ax
mov count2,ax
ldi ax,255 ;255 = ca. 16ms
mov count3,ax
ldi ax,255
mov count4,ax
rjmp zaehl
zaehl:
inc count1
cpse count1,count4
rjmp zaehl
ldi ax,0
mov count1,ax
inc count2
cpse count2,count3
rjmp zaehl
ret
;********
;LCD init
;********
func_set_:
sbi portd,e ;switch lcd on
rcall w_1ms ;wait 1ms
ldi lcd_temp,0b00100001 ;0b00101000 = 4 bits mode
out portd,lcd_temp
cbi portd,e
ret
func_set: ; set 4 bits mode
sbi portd,e ;switch lcd on ;wait 1ms
rcall w_1ms
ldi lcd_temp,0b00100100 ;0b00101000 = 4 bits mode
out portd,lcd_temp
cbi portd,e
rcall w_1ms
sbi portd,e ;switch lcd on ;wait 1ms
rcall w_1ms ;wait 1ms
ldi lcd_temp,0b10000100 ;0b00101000 = 4 bits mode
out portd,lcd_temp
cbi portd,e ;switch lcd off
ret
disp_onoff:
sbi portd,e ;switch lcd on
rcall w_1ms ;wait 1ms
ldi lcd_temp,0b00000100 ;display on/off
out portd,lcd_temp
cbi portd,e ;switch lcd off
rcall w_1ms
sbi portd,e ;switch lcd on ;wait 1ms
rcall w_1ms
ldi lcd_temp,0b11100100 ;0b00101000 = 4 bits mode
out portd,lcd_temp
cbi portd,e ;switch lcd off
ret
clear: sbi portd,e ;switch lcd on
rcall w_1ms ;wait 1ms
ldi lcd_temp,0b00000100 ;display clear
out portd,lcd_temp
cbi portd,e ;switch lcd off
rcall w_1ms ;wait 1ms
sbi portd,e ;switch lcd off
rcall w_1ms ;wait 1ms
ldi lcd_temp,0b00010100 ;display clear
out portd,lcd_temp
cbi portd,e ;switch lcd off
ret
entry_mode:
sbi portd,e ;switch lcd on
rcall w_1ms ;wait 1ms
ldi lcd_temp,0b00000100 ;entry mode
out portd,lcd_temp
cbi portd,e ;switch lcd off
rcall w_1ms ;wait 1ms
sbi portd,e ;switch lcd off
rcall w_1ms ;wait 1ms
ldi lcd_temp,0b01100100 ;entry mode
out portd,lcd_temp
cbi portd,e ;switch lcd off
ret
ret_home:
sbi portd,e ;switch lcd on
rcall w_1ms ;wait 1ms
ldi lcd_temp,0b00000100 ;00000010;return home befehl
out portd,lcd_temp
cbi portd,e ;switch lcd off
rcall w_1ms ;wait 1ms
sbi portd,e ;switch lcd off
rcall w_1ms ;wait 1ms
ldi lcd_temp,0b00100100 ;entry mode
out portd,lcd_temp
cbi portd,e ;switch lcd off
ret
sh_right:
sbi portd,e ;switch lcd on
rcall w_1ms ;wait 1ms
ldi lcd_temp,0b00010100 ;function shift right
out portd,lcd_temp
cbi portd,e ;switch lcd off
rcall w_1ms ;wait 1ms
sbi portd,e ;switch lcd off
rcall w_1ms ;wait 1ms
ldi lcd_temp,0b11000100 ;function shift right
out portd,lcd_temp
cbi portd,e ;switch lcd off
ret
sh_left:
sbi portd,e ;switch lcd on
rcall w_1ms ;wait 1ms
ldi lcd_temp,0b00010100 ;function shift left
out portd,lcd_temp
cbi portd,e ;switch lcd off
rcall w_1ms ;wait 1ms
sbi portd,e ;switch lcd off
rcall w_1ms ;wait 1ms
ldi lcd_temp,0b10000010 ;function shift left
out portd,lcd_temp
cbi portd,e ;switch lcd off
ret
x_set:
cpse x_counter,col ;if x_counter = col
rjmp x_high
ret
x_high:
sbi portd,e ;switch lcd on
rcall w_1ms ;wait 1ms
ldi lcd_temp,0b00010100 ;move cursor right
out portd,lcd_temp
cbi portd,e ;switch lcd off
rcall w_1ms ;wait 1ms
sbi portd,e ;switch lcd off
rcall w_1ms ;wait 1ms
ldi lcd_temp,0b01000100 ;move cursor right
out portd,lcd_temp
cbi portd,e ;switch lcd off
inc x_counter ;increase x_counter
rjmp x_set ;and x_set again
line1:
rcall ret_home ;ret_home
ldi x_counter,1 ;set counter to 1
rcall x_set
rjmp send1 ;begin to send
line2:
rcall ret_home ;rethome
sbi portd,e ;switch lcd on
rcall w_1ms ;wait 1ms
ldi lcd_temp,0b11000100 ;upperline
out portd,lcd_temp
cbi portd,e ;switch lcd on
rcall w_1ms ;wait 1ms
sbi portd,e ;switch lcd on
rcall w_1ms ;wait 1ms
ldi lcd_temp,0b00000100 ;upperline
out portd,lcd_temp
cbi portd,e ;switch lcd on
ldi x_counter,1 ;counter = 1
rcall x_set ;goto x
rjmp send1 ;begin to send
send1:
;;;;;lpm ;load zeichen
ld text,Z+
ldi cx,0
cpse text,cx ;if there are still characters
rjmp send2 ;then send it
rjmp send_end ;else go back
send2:
sbi portd,e ;switch lcd on
sbi portd,rs ;send data
rcall w_1ms ;wait 1ms
mov lcd_temp,text
ori lcd_temp,0b00001100
out portd,lcd_temp ;write data to port
cbi portd,e ;switch lcd off
rcall w_1ms
sbi portd,e ;switch lcd on
;sbi portd,rs ;send data
rcall w_1ms
mov lcd_temp,text
rol lcd_temp
rol lcd_temp
rol lcd_temp
rol lcd_temp
ori lcd_temp,0b00001100
out portd,lcd_temp ;write data to port
rjmp send3
send3:
cbi portd,e ;switch lcd off
cbi portd,rs ;data = instruction
rjmp send1
send_end:
cbi portd,e ;switch lcd off
cbi portd,rs ;data = instruction
ret ;go back
init_lcd:
ldi ax,10 ;30 ms
rcall delay
rcall func_set_
rcall w_16ms ;wait16ms
rcall func_set_
rcall w_16ms ;wait16ms
rcall func_set_
rcall w_16ms ;wait16ms
rcall func_set_
rcall w_16ms ;wait16ms
rcall func_set ;function set
ldi ax,10 ;30 ms
rcall delay
rcall w_5ms ;wait 5ms
rcall func_set ;function set
rcall w_1ms ;wait 1ms
rcall func_set ;function set
rcall w_5ms ;wait 1ms
rcall func_set ;function set
rcall w_5ms ;wait 1ms
rcall disp_onoff ;display on/off
rcall w_5ms ;wait 1ms
rcall clear ;clear display
rcall w_5ms ;wait 1ms
rcall entry_mode ;entry mode
rcall w_5ms ;wait 1ms
rcall func_set ;function set
rcall w_5ms ;wait 1ms
rcall disp_onoff ;display on/off
rcall w_5ms ;wait 1ms
rcall entry_mode ;entry mode
rcall w_5ms ;wait 1ms
;****************************************
;write init text to display
;****************************************
;write first row on display
;load first 16 char to string
ldi ZH,high(F_TABLE*2)
ldi ZL,low(F_TABLE*2) ;init Z-pointer
ldi YH,high(P_string)
ldi YL,low(P_string) ;init Y-pointer
ldi ax,16
rcall flash2ram ;copy 17 bytes
;load addres to string
ldi YH,high(P_string)
ldi YL,low(P_string+16) ;init Y-pointer
;place addres from 4021 in the variable addr
;-------------------
;in ax,pinc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;take addres from 4021
ldi ex,0
ldi fx,1
ldi hx,0
ldi dx,0b10111111 ;strobe hoog 00000010
out portb,dx
ldi ax,1 ;ax bx cx for delay!!!!
rcall delay
ldi dx,0b00111111 ;strobe laag
out portb,dx
ldi ax,1 ;ax bx cx for delay!!!!
rcall delay
loop10: ;start loop
sbis pinb,5 ;porta pin 5 high? Skip next inst. if bit 0 in Port a set
rjmp loop15 ; Bit not set
or hx,fx
loop15:
lsl fx ;set bit een plaats naar links
ldi dx,0b01111111 ;clock hoog 00000001
out portb,dx
ldi ax,1 ;ax bx cx for delay!!!!
rcall delay
ldi dx,0b00111111 ;clock laag
out portb,dx
ldi ax,1 ;ax bx cx for delay!!!!
rcall delay
inc ex
ldi dx,8
cp ex,dx
brne loop10
;hx = status jumpers now
mov ax,hx
sts jumpers,ax ;store status jumpers
;for pc make addres
ldi dx,0b00111111
and ax,dx ;2 high bits not use for addres <64!
mov bx,ax
ldi cx,32
add ax,cx ;addres + 32
sts addr,ax ;store addres
mov ax,bx
;from bin to decimal AX= LSD BX=MSD
clr bx ;clear result MSD
bBCD8_1:subi AX,10 ;input = input - 10
brcs bBCD8_2 ;abort if carry set
inc BX ;inc MSD
rjmp bBCD8_1 ;loop again
bBCD8_2:subi AX,-10 ;compensate extra subtraction
;write addres to string
ldi cx,48
add ax,cx
add bx,cx
mov text,bx
st Y+,text ;store data to BLOCK2
mov text,AX
st Y+,text ;store data to BLOCK2
;write 2 x space to string
ldi dx,32
mov text,dx
st Y+,text ;store data to BLOCK2
st Y+,text ;store data to BLOCK2
;end with zero
ldi dx,0
mov text,dx
st Y+,text ;store data to BLOCK2
;write string on display
ldi zl,low(P_string) ;set pointer to
ldi zh,high(P_string) ;the text
ldi col,1 ;set column
rcall line1 ;set line
;write second row to string
ldi ZH,high(F_TABLE2*2)
ldi ZL,low(F_TABLE2*2) ;init Z-pointer
ldi YH,high(P_string)
ldi YL,low(P_string) ;init Y-pointer
ldi ax,20
rcall flash2ram
;write string to display
ldi zl,low(P_string) ;set pointer to
ldi zh,high(P_string) ;the text
ldi col,1 ;set column
rcall line2 ;set line
rjmp main ;let's go...
;***************************************************************************
;*
;* "char_ram"
;*
;* This subroutine copies a block of data from the rs_port in a block of SRAM
;* The following parameters must be set up prior to calling the subroutine:
;*
;;* Y-pointer: start of RAM area to copy to
;* ramsize : size of block to copy
;***************************************************************************
;***** Code
;char_ram:
;char_ram1:
; sbi ucr,rxen ;set reciver bit...
; sbis usr,rxc ;wait for a valuable
; rjmp char_ram1
; in text,udr ;read valuable
; cbi ucr,rxen ;clear register
; st Y+,text ;store data to BLOCK2
; dec ax ;
;char_ram2:
; sbi ucr,rxen ;set reciver bit...
; sbis usr,rxc ;wait for a valuable
; rjmp char_ram2
; in text,udr ;read valuable
; cbi ucr,rxen ;clear register
; st Y+,text ;store data to BLOCK2
; dec ax ;
; brne char_ram1 ;if not done, loop more
; ldi dx,0
; mov text,dx ;eindig string met een null
; st Y+,text ;store data to BLOCK2
; ret
;okgedeelte:
; rcall rs_rec
; st Y+,text ;store data to BLOCK2
; dec ax ;
; brne char_ram ;if not done, loop more
;
; ldi dx,0
; mov text,dx ;eindig string met een null
; st Y+,text ;store data to BLOCK2
; ret
;***************************************************************************
;*
;* "flash2ram"
;*
;* This subroutine copies a block of data from the Program memory (Flash)
;* to the internal SRAM. The following parameters must be set up prior to
;* calling the subroutine:
;* Z-pointer: Flash block start address x 2 (WORD oriented code segment)
;* Y-pointer: ram block start address
;* romsize: block size
;*
;* Number of words :5 + return
;* Number of cycles :10 x block size + return
;* Low Registers used :1 (r0)
;* High Registers used :1 (flashsize)
;* Pointers used :Y, Z
;*
;***************************************************************************
;***** Subroutine Register variables
;***** Code
flash2ram:
lpm ;get constant
st Y+,text ;r0 ;store in SRAM and increment Y-pointer
adiw ZL,1 ;increment Z-pointer
dec ax
brne flash2ram ;if not end of table, loop more
ret
;***************************************************************************
;*
;* "ram2ram"
;*
;* This subroutine copies one block of data from one SRAM area to another.
;* The following parameters must be set up prior to calling the subroutine:
;*
;* Z-pointer: start of RAM area to copy from
;* Y-pointer: start of RAM area to copy to
;* ramsize : size of block to copy
;*
;* Number of words :4 + return
;* Number of cycles :6 x block size + return
;* Low Registers used :1 (ramtemp)
;* High Registers used :1 (ramsize)
;* Pointers used :Y, Z
;*
;***************************************************************************
ram2ram:
ld text,Z+ ;get data from BLOCK1
st Y+,text ;store data to BLOCK2
dec ax ;
brne ram2ram ;if not done, loop more
ret
;**********************************************************************
;subroutine to receive 1 byte from the uartt
;text :received char
;**********************************************************************
;rs_rec:
; sbi ucr,rxen ;set reciver bit...
; sbis usr,rxc ;wait for a valuable
; rjmp rs_rec
; in text,udr ;read valuable
; cbi ucr,rxen ;clear register
; ret
;**********************************************************************
;subroutine for transmit a byte to the uart
;text :char to transmit
;**********************************************************************
;rs_send: ;*******write to port
; sbi ucr,txen ;set sender bit
; sbis usr,udre ;wait till register is cleared
; rjmp rs_send
; out udr,text ;send char to rs232
; cbi ucr,txen ;clear sender bit
; ret ;go back
;************************************************************
;subroutine for delay
;ax= 5 = 1/2sec
;************************************************************
DELAY:
; ldi ax,5 ;triple nested FOR loop
cagain: ldi bx,255 ;giving about 1/2 second
magain: ldi cx,255 ;delay on 4 MHz clock
fagain: dec cx
brne fagain
dec bx
brne magain
dec ax
brne cagain
ret
;***************************************************************************
;*************************************
;main program
;*************************************
;***************************************************************************
main:
cbi portb,1 ;set uitgang 1 portb show init OK patch 15-3-2002
cbi portb,3 ;3 enable rs232 for input
main1:
;receive data for 9bit and addres
main2: ;255 received?
sbi ucr,rxen ;set receiver bit...
sbis usr,rxc ;wait for a valuable
rjmp main2
in text,udr ;read valuable
cbi ucr,rxen ;clear register
ldi ex,10
cp text,ex ;10 received?
brne main2 ;nee back
main3: ;255 received?
sbi ucr,rxen ;set reciver bit...
sbis usr,rxc ;wait for a valuable
rjmp main3
in text,udr ;read valuable
cbi ucr,rxen ;clear register
ldi ex,10
cp text,ex ;10 received?
brne main2 ;nee back
main5: ;addres received?
sbi ucr,rxen ;set receiver bit...
sbis usr,rxc ;wait for a valuable
rjmp main5
in text,udr ;read valuable
cbi ucr,rxen ;clear register
lds dx,addr
cp text,dx
brne main2 ;No
main10: ;received char == addres
cbi portb,2 ;2 led receive bussy
;get data rs485
sbi ucr,rxen ;set reciver bit...
sbis usr,rxc ;wait for a valuable
rjmp main10
in text,udr ;read valuable
cbi ucr,rxen ;clear register
com text
out porta,text ;set porta
main20: ;get the next 40 char for the display
;get first 20 char and place it in P_string
; cbi portb,3 ;enable rs232 in
; ldi YH,high(P_string) ;(not necessary in this specific case)
ldi YL,low(P_string) ;init Y-pointer
ldi ax,40 ;20
;get next 20 char and place it in P_string2
; ldi YH,high(P_string2) ;(not necessary in this specific case)
;x ldi YL,low(P_string2) ;init Y-pointer
;x ldi ax,20
;x rcall char_ram ;copy 20 bytes +0
main50: ;copy 40 bytes from rs485 to ram
sbi ucr,rxen ;set reciver bit...
sbis usr,rxc ;wait for a valuable
rjmp main50
in text,udr ;read valuable
cbi ucr,rxen ;clear register
st Y+,text ;store data to BLOCK2
dec ax ;
; brne char_ram1 ;if not done, loop more
main51:
sbi ucr,rxen ;set reciver bit...
sbis usr,rxc ;wait for a valuable
rjmp main51
in text,udr ;read valuable
cbi ucr,rxen ;clear register
st Y+,text ;store data to BLOCK2
dec ax ;
main52:
sbi ucr,rxen ;set reciver bit...
sbis usr,rxc ;wait for a valuable
rjmp main52
in text,udr ;read valuable
cbi ucr,rxen ;clear register
st Y+,text ;store data to BLOCK2
dec ax
main53:
sbi ucr,rxen ;set reciver bit...
sbis usr,rxc ;wait for a valuable
rjmp main53
in text,udr ;read valuable
cbi ucr,rxen ;clear register
st Y+,text ;store data to BLOCK2
dec ax
cpi ax,0
brne main50 ;if not done, loop more
ldi dx,0
mov text,dx ;eindig string met een null
st Y+,text ;store data to BLOCK2
main100: ;transmit addres and data from portc
rcall w_5ms
;rcall w_5ms ;patch 14-2
sbi portb,3 ;enable rs485 out
lds text,addr ;first send addres
main101: ;Write to rs485
sbi ucr,txen ;set sender bit
sbis usr,udre ;wait till register is cleared
rjmp main101
out udr,text ;send addres to rs485
cbi ucr,txen ;clear sender bit
;send portb to rs485
in ax,pinc ;send info portb to rs485
main102: ;write to rs485
sbi ucr,txen ;set sender bit
sbis usr,udre ;wait till register is cleared
rjmp main102
out udr,ax ;send PINC to rs485
cbi ucr,txen ;clear sender bit
;send again addres
lds text,addr ;send again addres
main103: ;write to rs485
sbi ucr,txen ;set sender bit
sbis usr,udre ;wait till register is cleared
rjmp main103
out udr,text ;send addres to rs485
cbi ucr,txen ;clear sender bit
rcall w_1ms ;patch 22-1-2002
cbi portb,3 ;0;enable rs232 for input
sbi portb,2 ;led receive bussy
main150:
;write strings to display
;first P_string to row 1
ldi zl,low(P_string) ;set pointer to
ldi zh,high(P_string) ;the text
ldi col,1 ;set column
rcall line1 ;set line
;P_string2 to display
ldi zl,low(P_string+20) ;set pointer to
ldi zh,high(P_string) ;the text
ldi col,1 ;set column
rcall line2 ;set line
main_end:
;cbi portb,3 ;0;enable rs232 for input
;sbi portb,2 ;led receive bussy
rjmp main1 ;
;*************
;text constant FLASH EEPROM
;*************
F_TABLE: ;17 lang
.db 32 ,32 ,68 ,67 ,73 ,45 ,66 ,85 ,83 ,32 ,65 ,100,100,114,58 ,32,0
; D C I - B U S A d d r :
F_TABLE1: ;5 lang
.db 51 ,55,32,42,0
;
F_TABLE2:
.db 32, 119,97 ,105,116,105,110,103,32 ,102,111,114,32 ,100,97 ,116,97,46,87,32,0
; w a i t i n g f o r d a t a . .
PS: CASO VC TENTE SIMULA-LO NOPROTEUS , E COMO EU SOU NOVATO EM AVR

, GOSTARIA DE SABER COMO FAZER PARA AJUSTAR MELHOR O TEXTO NO LCD.
VALEU
KILB
VENDO BRASILIA 78 - AZUL CALCINHA - RODA GAIUCHA, PNEU TALA LARGA E TOCA FITA RODSTAR, TRATAR NO BUTECO