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.

12c508 with rs232/ character sent and or received is off

Status
Not open for further replies.

wejos

Member
hi guys,

i am using the "rs232 code" from nigel's tutorial in my serial communication experiment. it worked well with my 16f84 but i was thinking to port the code to 12c508 because since it had lesser pins had some appeal to me. it was not an easy transition from 16f84 to 12c508, i ran into a lot of obstacle and tried to figure out what the problem was. like i did not yet know at the time you cannot call "CALL" twice, using RETURN is not allowed also, plus the OSCCAL part and the different setting you have to use when assigning TRIS. But i'm stuck again and don't know what to do next. the character that i send out from the pic is off. plus the character i send out to the pic like "b", when it should be "a" to make GPIO,0x01 go high, still make GP1 go high.

by the way i am using the internal oscillator of 4Mhz

here's the code:

Code:
	LIST P=12C508A
	#INCLUDE "P12C508A.INC"


	__CONFIG _MCLRE_OFF & _CP_OFF & _WDT_ON & _IntRC_OSC 


Rcv_Byte     equ    0x07    
Bit_cntr     equ    0x08
Delay_Count  equ    0x09
Xmit_Byte    equ    0x0A
Baf          equ    0x0B
BUF          equ    0x0C
CounterC     equ    0x0D


		ORG     0x1FFA

		ORG		0x000				

 	GOTO	INIT				

INIT

	MOVWF	OSCCAL				
								
							
	MOVLW b'00000001'
	TRIS  06
    OPTION  				
    CLRF   GPIO
						                      




Rcv_RS232   BTFSS   GPIO,0x03
            GOTO    XMIT_RS232 
            BTFSC   GPIO,0x00     
            GOTO    Rcv_RS232
            CALL    Start_Delay	    
            BTFSC   GPIO,0x00      
            GOTO    Rcv_RS232
            MOVLW   0x08            
            MOVWF   Bit_cntr
            CLRF    Rcv_Byte
Next_RcvBit CALL    Bit_Delay
            BTFSS   GPIO,0x00
            BCF     STATUS,C
            BTFSC   GPIO,0x00
            BSF     STATUS,C
            RRF     Rcv_Byte,f
            DECFSZ  Bit_cntr,f      
            GOTO    Next_RcvBit
            CALL    Bit_Delay
            MOVF    Rcv_Byte,W
            MOVF    Baf,W
            MOVWF   Baf
            xorlw   0x61			
            btfss   STATUS, Z
            bsf     GPIO,0x01
            goto    Rcv_RS232
XMIT_RS232  MOVWF   Xmit_Byte             
            MOVLW   0x08                  
            MOVWF   Bit_cntr
            BCF     GPIO, 0x05
            CALL    Bit_Delay
Ser_Loop    RRF     Xmit_Byte,f         
            BTFSS   STATUS,C
            BCF     GPIO,0x05
            BTFSC   STATUS,C
            BSF     GPIO,0x05
            CALL    Bit_Delay
            DECFSZ  Bit_cntr,f         
            RRF     Xmit_Byte,f         
            BTFSS   STATUS,C
            BCF     GPIO,0x05
            BTFSC   STATUS,C
            BSF     GPIO,0x05
            BSF     GPIO,0x05
            CALL    Bit_Delay
            GOTO    Rcv_RS232


Start_Delay MOVLW   0x0C
            MOVWF   Delay_Count
Start_Wait  NOP
            DECFSZ  Delay_Count,f
            GOTO    Start_Wait
            RETLW 00h

Bit_Delay   MOVLW   0x18
            MOVWF   Delay_Count
Bit_Wait    NOP
            DECFSZ  Delay_Count,f
            GOTO    Bit_Wait
            RETLW 00h


delay1:	
;PIC Time Delay = 0.50000200 s with Osc = 4000000 Hz
		movlw	D'5'
		movwf	CounterC
		
loopp	decfsz	CounterC,1
		goto	loopp
		retlw	00h	 




			END

screenshot of simulation:


thank you very much
 

Attachments

  • untitled.JPG
    untitled.JPG
    94.9 KB · Views: 273
i'm sorry nigel but because it's not available in our city. i had to buy in bulk also if i have them shipped to my country.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top