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.

need help please

Status
Not open for further replies.

MLOTZ

New Member
hi looks like my programming skills isn't so good. I'm sending a signal at 9600 bps to my pic16f628a RB2(RX) PIN. BUT FOR SOME REASON DOES THE PIC NOT UPDATING THE "RCREN" REGISTER.

IF POSSIBLE CAN SOMEBODY TELL ME WHERE TO GET A EXAMPLE PROGRAM TO SEE WHERE MY PROBLEM MIGHT BE?
 
hi,

Please post your PIC coding.

Do you mean RCREG ?
 
Last edited:
LIST P=16F628A, R=DEC ; Use the PIC16F628A and decimal system
processor 16F628A
#include <P16F628A.INC> ; Include header file

S_IN EQU 0X20

INIT BSF STATUS,RP0
MOVLW 0X00
MOVWF TRISA
MOVLW B'00000110'
MOVWF TRISB
;--------------------------------------------
;MOVLW 0X0F
;MOVWF 0X92 ;PR2
;--------------------------------------------
MOVLW 0X07
MOVWF CMCON
MOVLW B'00100110'
MOVWF PIE1 ;PIE1
MOVLW 0X80
MOVWF INTCON
;--------------------------------------------
; ------------------------------------
; SET BAUD RATE TO COMMUNICATE WITH PC
; ------------------------------------
; Boot Baud Rate = 9600, No Parity, 1 Stop Bit
;
movlw 0x19 ; 0x19=9600 bps (0x0C=19200 bps)
movwf SPBRG
movlw b'10100110' ; brgh = high (2)
movwf TXSTA ; enable Async Transmission, set brgh
bcf STATUS,RP0 ; RAM PAGE 0
movlw b'10010100' ; enable Async Reception
movwf RCSTA
MOVLW 0X0F
MOVWF T2CON

; -------------------------------------------
; RECEIVE CHARACTER FROM RS232 AND STORE IN W
; -------------------------------------------
; This routine does not return until a character is received.
;
receive btfss PIR1,RCIF ; (5) check for received data
goto receive
movf RCREG,W ; save received data in W

START MOVWF S_IN
MOVF S_IN,W
MOVWF PORTA

END
 
You could check my PIC tutorials, the last RS232 one uses the USART, although on a 16F876/7 at 20MHz, but it only needs very minor changes for the 16F628.
 
hi mlotz,

Check why you have the UART RX interrupt enabled, when you polling, also where ISR ?
 
Last edited:
I Know My Program Is Half, But I'm Batteling With That Rcreg Why Isn't It Working. Don't You Have A Example That I Can Compare?
 
hi mlotz,
When you say your program is Half, do you mean you have only posted half the program listing?.

Check why you have the UART RX interrupt enabled, when you are polling RX, also where is the ISR ?

Have you looked at the datasheet regarding Interrupts?
 
Last edited:
hi ok I've disabled all my interrupts.

Will my program work without ISR?

I'm simulating it in pic simulator IDE,but for some reason the data that I'm sending to RB2 is not updated in my RCREG register.

Will you look at my program again PLEASE

**********************************************************

LIST P=16F628A, R=DEC ; Use the PIC16F628A and decimal system
processor 16F628A
#include <P16F628A.INC> ; Include header file

S_IN EQU 0X20
org 0x00


start BSF STATUS,RP0 ; RAM PAGE 1
MOVLW 0X00
MOVWF TRISA
MOVLW B'00000110' ;set RB2,RB3 as inputs
MOVWF TRISB
;--------------------------------------------
;--------------------------------------------
MOVLW 0X07 ;switch comparators off
MOVWF CMCON
;--------------------------------------------
; ------------------------------------
; SET BAUD RATE TO COMMUNICATE WITH PC
; ------------------------------------
; Boot Baud Rate = 9600, No Parity, 1 Stop Bit
;
movlw 0x19 ; 0x19=9600 bps (0x0C=19200 bps)
movwf SPBRG
movlw b'00100100' ; brgh = high (2)
movwf TXSTA ; enable Async Transmission, set brgh
BCF STATUS,RP0 ; RAM PAGE 0
movlw b'10010000' ; enable Async Reception
movwf RCSTA
MOVF RCREG,W
; -------------------------------------------
; RECEIVE CHARACTER FROM RS232 AND STORE IN W
; -------------------------------------------
; This routine does not return until a character is received.
;
receive btfss PIR1,RCIF ; (5) check for received data
goto receive
movf RCREG,W ; save received data in W

MOVWF S_IN ;SENDING DATA OUT ON PORTA
MOVF S_IN,W
MOVWF PORTA

END
 
Last edited:
hi,

Will my program work without ISR?

A ISR is an 'Interrupt Service Routine'.

If you have no interrupts enabled, you don't need an ISR.

I'll have another look at coding
 
hi mlotz,

If you add 'goto receive' just before the END statement, [so it keeps repeat testing RX] it works OK in my PIC sim.
 
i think i found my problem in my simulation I'm using the software UART simulator interface and not the hardware UART simulator interface.


After 3 days of battling with this problem and my program was ok!!!!!!

I need a drink.

Thanks for everybody's help.
I'm off to the BAR.
 
This is why it always pays to double check EVERYTHING.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top