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.

12F629 GP3

Status
Not open for further replies.

Kingpin094

New Member
Is there any reason why GP3 couldn't be used as an RX pin for a soft
UART? I know that it is input only. I have the chip setup to use a
external crystal. The chip seems to run fine but I can't get the UART
working correctly. I know the code for the UART works because I
have run it on a 16F819 and it worked fine.

Thanks
kingpin094
 
GP3 is also the MCLR pin (reset). If you want to use it as an input you have to make sure you set MCLR to internal in the configuration word.
 
I use the MCLR/GP3 pin as the bit-banged RX input on a 12F683 and it works fine...

Regards, Mike
 

Attachments

  • rs232_circuit_for_12f683.jpg
    rs232_circuit_for_12f683.jpg
    47.9 KB · Views: 1,158
good day to all

MIKE, do u mind if i can go though ur source code ??

i tried ti run my source code but i got numbers only means if i want to press (A) or anything else i can not get it


thanx for help
 
The 12F675 version uses 4-MHz INTOSC and TMR0 interrupts and the 12F683 version uses 8-MHz INTOSC and TMR2 interrupts. Both versions are half-duplex 9600 baud.

Regards, Mike

Code:
;******************************************************************
;*                                                                *
;*  Filename: 12F675 Serial Demo 3.asm                            *
;*    Author: Mike McLaren, K8LH   (k8lh@arrl.net)                *
;*      Date: 16-Jan-06  (last revision 30-Mar-07)                *
;*                                                                *
;*   Half Duplex Bit-Banged 9600 Baud Serial I/O Demo             *
;*    (2-Pin Version with 8-Byte Circular RX Buffer)              *
;*                                                                *
;*  ·Uses 12F675 INTOSC running at 4-MHz                          *
;*  ·Bit rate error 0.16% plus or minus 1.0% for INTOSC           *
;*  ·Bit-banged 9600 baud serial I/O                              *
;*    ·Half Duplex (should not TX and RX simultaneously)          *
;*    ·TMR0 interrupts at 104-usec intervals (every 104           *
;*     instruction cycles) and IOC (interrupt on change)          *
;*     for RX start bit leading edge detection on RXPIN           *
;*    ·Circular 8-byte RX character buffer                        *
;*    ·Inverted TX and RX signals (MAX232A or similar             *
;*     inverting RS-232 interface required)                       *
;*  ·Relatively small - the ISR and the support routines          *
;*   Init232, Put232, Get232, and PutString use 124 words         *
;*   of code space at locations 0004 through 007F and 20          *
;*   of 64 RAM locations for variables and RX buffer...           *
;*  ·Worst case 51% ISR instruction cycle 'overhead'              *
;*   (54-usecs) when a complete RX character is added to          *
;*   the circular buffer once every 1.04-msecs...                 *
;*                                                                *
;*                                                                *
;*     MPLab: 7.30    (tabs=8)                                    *
;*     MPAsm: 5.01                                                *
;*                                                                *
;******************************************************************
Code:
;******************************************************************
;*                                                                *
;*  Filename: 12F683 Half-Duplex 9600 Demo.asm                    *
;*    Author: Mike McLaren, K8LH   (k8lh_at_arrl.net)             *
;*      Date: 02-Jun-05  (last revision 02-Dec-05)                *
;*                                                                *
;*   Half Duplex Bit-Banged 9600 Baud Serial I/O Demo             *
;*   (with 16-byte circular receive character buffer)             *
;*                                                                *
;*  ·Uses 12F683 INTOSC running at 8-MHz                          *
;*  ·Bit rate error 0.16% plus or minus 1.0% for INTOSC           *
;*  ·Bit-banged 9600 baud serial I/O                              *
;*    ·Half Duplex (should not TX and RX simultaneously)          *
;*    ·TMR2 interrupts at 104-usec intervals (every 208           *
;*     instruction cycles) and IOC (interrupt on change)          *
;*     for RX start bit leading edge detection on RXPIN           *
;*    ·Circular 16-byte RX character buffer                       *
;*    ·Inverted TX and RX signals (MAX232A or similar             *
;*     inverting RS-232 interface required)                       *
;*  ·Relatively small - the ISR and the support routines          *
;*   Init232, Put232, and Get232 use 102 words of code            *
;*   space at locations 0004 through 0069                         *
;*  ·Worst case 23% ISR 'overhead' (24-usecs) when a              *
;*   complete RX character is added to the circular               *
;*   buffer once every 1.04-msecs while receiving                 *
;*                                                                *
;*     MPLab: 7.21    (tabs=8)                                    *
;*     MPAsm: 4.02                                                *
;*                                                                *
;******************************************************************
 

Attachments

  • 12F683 Serial Demo.asm.txt
    19.3 KB · Views: 192
  • 12F675 Serial Demo.asm.txt
    19.8 KB · Views: 278
Hi Mike,
I need some help for beginner. I want read from rs232 to 12f675. Have you some code in MPASM for study?
I found cheap RFID module ID12 , so I want use them as simple code lock.
RS232 is big math for me...
Thank You!
ppt
 
Hi,
Yes, I want to read rs232 using this pic with internal osc 4mhz. I looking for code simplest as possible, maybe I understand how it works then.
Thank you.
 
Well here's an RX subroutine I put together for someone over at Forum.Microchip that you can study and simulate. It's for "direct" connection (inverted). If you use a level converter IC then you should change the two btfss instructions to btfsc instructions.

Regards, Mike

Code:
;
;  K8LH General Purpose Serial RX Subroutine
;
rx232                           ; 9600 baud
        btfss   rxpin           ; start bit (1)? yes, skip, else
        goto    rx232           ; loop (wait)
        DelayCy(52*usecs)       ; delay 1/2 bit time
        movlw   8               ;
        movwf   count           ; count = 8
rxbit   DelayCy(104*usecs-7)    ; precise 104-usec bit timing
        clrc                    ; assume '0'
        btfss   rxpin           ; a '0' bit? yes, skip, else
        setc                    ; set to '1'
        rrf     rxdata,F        ; b0 comes first, b7 comes last
        decfsz  count,F         ; done? yes, skip, else
        goto    rxbit           ; get another bit
        return                  ;
Here's a general purpose DelayCy() macro if you need it;
Code:
;
clock   equ     4               ; 4, 8, 12, 16, or 20 MHz clock
usecs   equ     clock/4         ; cycles/usec operand multiplier

DelayCy macro   delay           ; 0..1027 cycles
     if delay > 3
        movlw   delay/4-1       ;
        addlw   -1              ; 4 cycle loop (14 bit core)
        skpnc                   ; borrow? yes, skip, else
        goto    $-2             ; loop again
     endif
     if delay%4 >= 2
        goto    $+1             ; delay%4 == 2 or delay%4 == 3
     endif
     if delay&1
        nop                     ; delay%4 == 1 or delay%4 == 3
     endif
        endm
 
Last edited:
Hi Mike,
Thank you very much for your code!
Seems prety simple and clear.
Macro for delay is big news for me...
I will try simulate and then post result!
 
It is pretty simple but there are some subtleties worth mentioning. The subroutine returns after sampling the eighth bit in the middle of the bit interval so you have about 140 instruction cycles (140 usecs) to do something else in your program before calling the subroutine again to collect the next incoming serial character. If you don't burn off at least 50 cycles (50 usecs) in your program before calling the subroutine again you risk sampling the eighth bit again and interpreting it as a 'start' bit if it happens to be a '0'.

Regards, Mike
 
Hi Mike,
If I understood ,I must insert 140usec delay between each call of this routine, right?
 
RE

Hi Mike,
Thank you very much for help.Your code does not work because I not understood how it
works.But I found this one and works:
rx232 nop
start_bit
btfsc rxpin ;btfss if connected via 22K resistor
goto start_bit ;btfsc if standard connection
call start_delay
btfsc rxpin ;btfss if connect via 22k resistor
goto start_bit ;btfsc if standard connection
movlw h'08'
movwf bit_cntr
clrf rcv_byte
receive call bit_delay_R ;btfss if standard connection
btfss rxpin ;btfsc if connect via 22k resistor
bcf STATUS,0
btfsc rxpin ;btfss if connect via 22k resistor
bsf STATUS,0 ;btfsc if standard connection
rrf rcv_byte,1
decfsz bit_cntr,1
goto receive
call bit_delay_R
return
bit_delay_R
movlw bit_K
movwf delay_cntr
loop_R nop
decfsz delay_cntr,1
goto loop_R
return
start_delay
movlw half_bit
movwf delay_cntr
loop_R2 nop
decfsz delay_cntr,1
goto loop_R2
return
 
Hi Mike, my name is Alfredo and I´m a chemistry teacher that has electronis as a hobby. I´m trying to understand your soft to do serial communicatio with a 12F675. I made an adaptation to the 12F629 and is working very well. However, as I´m not a IT guy I´m not understanding the instruction : xorlw "1"^"0". What does it means?
Thank you
Alfredo
Curitiba- Brasil
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top