![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | LinkBack | Thread Tools | Display Modes |
| | (permalink) |
| 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? | |
| |
| | (permalink) |
| 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. | |
| |
| | (permalink) |
| 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 | |
| |
| | (permalink) |
| Typing Error!!! Yes "rcreg" Sorry | |
| |
| | (permalink) |
| 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. | |
| |
| | (permalink) |
| Thanks Nigel | |
| |
| | (permalink) |
| 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. | |
| |
| | (permalink) |
| 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? | |
| |
| | (permalink) |
| 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 | |
| |
| | (permalink) |
| 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. | |
| |
| | (permalink) |
| 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. | |
| |
| | (permalink) |
| 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. | |
| |
| | (permalink) |
| sorry about start and end anything else wrong? | |
| |
| | (permalink) |
| 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/ | |
| |
| | (permalink) |
| 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/ | |
| |