Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

UART-simulation doubt.

Status
Not open for further replies.

asp1987

New Member
Hi..
I am trying to initialise PIC UART at 115200 baud rate.I wrote a small program for that purpose and used oshonsoft simulator's Oscilloscope tool for viewing the output of the TRANSMIT pin. Two problems..
1. It always remain low. 'U' is 01010101.so there should be HIGHs and LOWs,right?
2. It takes about 1000uS to transmit character 'U' at 20 Mhz(16F877A).Shouldn't it be around 86.8 uS(8 data+1 stop+1 start bit)?
Plz tell me if there is any mistakes in the code.

;--------------------------------------------------------
begin
bcf STATUS,RP1
bcf STATUS,RP0
;Interrupts
bcf INTCON,GIE ;turn gie off
btfsc INTCON,GIE
goto begin
;----------------------------------------------------
bsf STATUS,RP0 ;bank1
movlw 0x00
movwf TRISA
movwf TRISB
movwf TRISD
movwf TRISE
;----------------------------------------------------
;asynchronous-settings
movlw 0xC0 ; rc7 and rc6 as inputs
movwf TRISC ; 11000000 to trisc
movlw 0x0A ;(0x0A=115200 bps)
movwf SPBRG
movlw b'00100100' ;brgh = high
movwf TXSTA ;enable Async Transmission, set brgh
bcf STATUS, RP0 ;select bank 0
movlw b'10010000' ;enable Async Reception
movwf RCSTA
;-----------------------------------------------------
;PIE1,RCIE
bsf STATUS, RP0 ;select bank 1
bsf PIE1, RCIE ;enable interups on USART receive
bcf STATUS, RP0 ;select bank 0

;------------------------------------------------------
bsf INTCON, PEIE ;enable Peripheral interupts
bsf INTCON, INTE ;enable RB0/INT interupts
bsf INTCON, GIE ;global interrupt enable
;--------------------------------------------------
; code starts
movlw d'3'
movwf 0x20
abcd
movlw 0x55
call Send
decfsz 0x20,1
goto abcd
eh
nop ;so that i can see the transmission stopped
goto eh
;--------------------------------------------------------------------
Send
movwf TXREG
TransmitWait
bsf STATUS,RP0 ; bank1
WaitHere
btfss TXSTA,TRMT ;transmission is complete if high
goto WaitHere
bcf STATUS,RP0 ;bank0
return
;--------------------------------------------------------------------
 
uart in 16f877a

hi i am trying to send data through the Rc6 and recieve the same data through Rc7 and transfer on port b but the transmitted data and recieved data are not synchronous always. so i want to change to uart in 16f877a. can any one help me to locate uart pin and solve the problem so that i can recieve the same data. the code is as follows.


#include <16f877a.h>
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=20000000)
#use rs232(baud=1200, xmit=PIN_C6, rcv=PIN_C7) // Jumpers: 8 to 11, 7 to 12
#include<lcd.c>
#byte pa=0x05
#byte pb=0x06
#byte pc=0x07
#byte pd=0x08
#byte lcd=0x08

main() {
int a,b,c;
set_tris_a(0x2f);
set_tris_b(0x00);
set_tris_c(0x80);
set_tris_d(0x00);
setup_psp(psp_disabled);
setup_adc_ports( ALL_ANALOG );
setup_adc(ADC_CLOCK_INTERNAL );
lcd_init();

while (TRUE) {
putc(0x13);
set_adc_channel(0);
delay_ms(10);
b=read_adc();
getc();
pb=getc();
delay_ms(5000);
delay_ms(5000);
pb=0x00;
delay_ms(5000);
delay_ms(5000);
output_high(PIN_B0);
delay_us(500);
output_low(PIN_B0);
delay_us(500);

}
}
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top