Hi Everyone;
I made this program and works fine at 9600 or 2400bps, however if i put at for exemple 57600 or 19200, i don't receive the the chars correctly, can somebody help me;
PIC16F877A
4Mhz
Thanks
Code:
Code:
include "modedefs.bas"
DEFINE OSC 4
' VARIÁVEIS
' ====================================================================
DADOS var byte(4)
ID var byte(2)
' REGISTOS PINOUT 1 = IN; 0 = OUT
' ====================================================================
'76543210
TRISA = %00000001
TRISB = %00001111
TRISC = %10000000
TRISD = %00000000
TRISE = %00000000
ADCON1 = 7
' NOMES PINOUT
' ====================================================================
LED VAR PORTA.1
TX Var PORTC.6
RX VAR PORTC.7
' DEFINIÇÕES
' ====================================================================
DEFINE LCD_DREG PORTB ' LCD Data bits on PORTB
DEFINE LCD_DBIT 4 ' PORTB starting address
DEFINE LCD_RSREG PORTB ' LCD RS bit on PORTB
DEFINE LCD_RSBIT 3 ' LCD RS bit address
DEFINE LCD_EREG PORTB ' LCD E bit on PORTB
DEFINE LCD_EBIT 2 ' LCD E bit address
DEFINE LCD_BITS 4 ' LCD in 4-bit mode
DEFINE LCD_LINES 2 ' LCD has 2 rows
DEFINE LCD_COMMANDUS 2000 ' Set command delay time in us
DEFINE LCD_DATAUS 50 ' Set data delay time in us
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h
DEFINE HSER_BAUD 9600
DEFINE HSER_SPBRG 25
' INICIO PROGRAMA
' ====================================================================
Start:
LCDOUT $fe, 1
lcdout " Teste USB"
lcdout $FE,$C0," Por Hugo Oliveira"
pause 2000
Main:
toggle led
hserout ["Hugo "]
lcdout " Teste USB"
lcdout $FE,$C0," Hugo "
Pause 2000
toggle led
hserout ["Oliveira",cr]
LCDOUT $fe, 1
lcdout " Teste USB"
lcdout $FE,$C0," Oliveira "
Pause 2000
low led
' Rotina que espera por trama, ID, e Valor e compara
' ====================================================================
Recebe:
Hserin [wait("OK"),STR ID\2,str DAdos\4]
if id(0)="3" and id(1)="2" then
if DADOS(0)="H" and DADOS(1)="u" and DADOS(2)="g" and DADOS(3)="o" then
high led
LCDOUT $fe, 1
lcdout " Teste USB"
lcdout $FE,$C0,"Recebido H "
endif
if DADOS(0)="L" and DADOS(1)="u" and DADOS(2)="L" and DADOS(3)="u" then
low led
LCDOUT $fe, 1
lcdout " Teste USB"
lcdout $FE,$C0,"Recebido L "
endif
if DADOS(0)<>"L" and DADOS(0)<>"H" then
LCDOUT $fe, 1
lcdout " Teste USB"
lcdout $FE,$C0,"Recebido :",DADOS(0),DADOS(1),DADOS(2),DADOS(3)
endif
endif
goto Recebe
END
Bookmarks