Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
LinkBack Thread Tools Display Modes
Old 27th March 2007, 05:24 PM   (permalink)
Default need help please

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?
MLOTZ is offline  
Old 27th March 2007, 06:10 PM   (permalink)
Default

hi,

Please post your PIC coding.

Do you mean RCREG ?
__________________
Eric
"Good enough is Perfect"

PIC tutorials:
Gramo's: www.digital-diy.net/
Bill's: www.blueroomelectronics.com/

Last edited by ericgibbs; 27th March 2007 at 06:14 PM.
ericgibbs is offline  
Old 27th March 2007, 06:21 PM   (permalink)
Default

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
MLOTZ is offline  
Old 27th March 2007, 06:30 PM   (permalink)
Default

Typing Error!!!

Yes "rcreg"

Sorry
MLOTZ is offline  
Old 27th March 2007, 06:49 PM   (permalink)
Default

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.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 27th March 2007, 06:54 PM   (permalink)
Default

Thanks Nigel
MLOTZ is offline  
Old 27th March 2007, 06:55 PM   (permalink)
Default

hi mlotz,

Check why you have the UART RX interrupt enabled, when you polling, also where ISR ?
__________________
Eric
"Good enough is Perfect"

PIC tutorials:
Gramo's: www.digital-diy.net/
Bill's: www.blueroomelectronics.com/

Last edited by ericgibbs; 27th March 2007 at 06:57 PM.
ericgibbs is offline  
Old 27th March 2007, 07:07 PM   (permalink)
Default

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?
MLOTZ is offline  
Old 28th March 2007, 03:20 AM   (permalink)
Default

How about a higher level language such as Proton (PIC Basic) to do the work for you?

HSEROUT data

HSERIN data

But it’s not everyone’s cup of tea, personally I don’t like re-inventing the wheel
__________________
Spency.

PIC Micro's - Your mind is the limit

PIC's and interfacing with other devices - a PIC Basic Guide @ digital-diy.net
gramo is offline  
Old 28th March 2007, 08:51 AM   (permalink)
Default

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?
__________________
Eric
"Good enough is Perfect"

PIC tutorials:
Gramo's: www.digital-diy.net/
Bill's: www.blueroomelectronics.com/

Last edited by ericgibbs; 28th March 2007 at 08:53 AM.
ericgibbs is offline  
Old 28th March 2007, 10:27 AM   (permalink)
Question

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 by MLOTZ; 28th March 2007 at 10:40 AM.
MLOTZ is offline  
Old 28th March 2007, 10:34 AM   (permalink)
Default

There's no start address for the program, which is poor practice, but there's no finish to it either, so it will continually restart from the beginning.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 28th March 2007, 10:41 AM   (permalink)
Default

sorry about start and end anything else wrong?
MLOTZ is offline  
Old 28th March 2007, 10:50 AM   (permalink)
Default

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
__________________
Eric
"Good enough is Perfect"

PIC tutorials:
Gramo's: www.digital-diy.net/
Bill's: www.blueroomelectronics.com/
ericgibbs is offline  
Old 28th March 2007, 11:17 AM   (permalink)
Default

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.
__________________
Eric
"Good enough is Perfect"

PIC tutorials:
Gramo's: www.digital-diy.net/
Bill's: www.blueroomelectronics.com/
ericgibbs is offline  
Reply

Bookmarks

Thread Tools
Display Modes





All times are GMT. The time now is 08:15 AM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker