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.

Problem with Code: Help

Status
Not open for further replies.

Electrix

Member
This particular program is to send data from one PIC to another PIC. One of them is continously transmitting data (ASCII charc) and the other is polling the RCIF to receive the data. The problem is i'm keeping an LED to indicate that a byte has been successfully received. It's all working fine in the simulator, but when I see the actual test..the LED doesnt flash.

Code:
;**********************************************************************
;   This file is a basic code template for assembly code generation   *
;   on the PICmicro PIC16F73. This file contains the basic code       *
;   building blocks to build upon.                                    *  
;                                                                     *
;   If interrupts are not used all code presented between the ORG     *
;   0x004 directive and the label main can be removed. In addition    *
;   the variable assignments for 'w_temp' and 'status_temp' can       *
;   be removed.                                                       *                         
;                                                                     *
;   Refer to the MPASM User's Guide for additional information on     *
;   features of the assembler (Document DS33014).                     *
;                                                                     *
;   Refer to the respective PICmicro data sheet for additional        *
;   information on the instruction set.                               *
;                                                                     *
;**********************************************************************
;                                                                     *
;    Filename:	    xxx.asm                                           *
;    Date:                                                            *
;    File Version:                                                    *
;                                                                     *
;    Author:                                                          *
;    Company:                                                         *
;                                                                     * 
;                                                                     *
;**********************************************************************
;                                                                     *
;    Files required:                                                  *
;                                                                     *
;                                                                     *
;                                                                     *
;**********************************************************************
;                                                                     *
;    Notes:                                                           *
;                                                                     *
;                                                                     *
;                                                                     *
;                                                                     *
;**********************************************************************


	list		p=16f73		; list directive to define processor
	#include	<p16f73.inc>	; processor specific variable definitions
	
	__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _RC_OSC

; '__CONFIG' directive is used to embed configuration data within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.






;***** VARIABLE DEFINITIONS
w_temp		EQU	0x20		; variable used for context saving
w_temp1		EQU	0xA0		; reserve bank1 equivalent of w_temp 
status_temp	EQU	0x21		; variable used for context saving
pclath_temp	EQU	0x22		; variable used for context saving			
cnt500u		EQU 0x23		
cnt1m		EQU 0x24
cnt100m		EQU 0x25
cnt500m		EQU 0x26
cnt1s		EQU 0x27
cnt15s		EQU 0x28


;**********************************************************************
	ORG     0x000             ; processor reset vector

	clrf    PCLATH            ; ensure page bits are cleared
  	goto    main              ; go to beginning of program


	ORG     0x004             ; interrupt vector location

	movwf   w_temp            ; save off current W register contents
	movf	STATUS,w          ; move status register into W register
	bcf     STATUS,RP0        ; ensure file register bank set to 0
	movwf	status_temp       ; save off contents of STATUS register
	movf	PCLATH,w	  ; move pclath register into w register
	movwf	pclath_temp	  ; save off contents of PCLATH register


; isr code can go here or be located as a call subroutine elsewhere


	bcf     STATUS,RP0        ; ensure file register bank set to 0
	movf	pclath_temp,w	  ; retrieve copy of PCLATH register
	movwf	PCLATH		  ; restore pre-isr PCLATH register contents
	movf    status_temp,w     ; retrieve copy of STATUS register
	movwf	STATUS            ; restore pre-isr STATUS register contents
	swapf   w_temp,f
	swapf   w_temp,w          ; restore pre-isr W register contents
	retfie                    ; return from interrupt



main

; remaining code goes here

	BANKSEL	TRISB
	clrf	TRISB

	movlw	b'01000000'
	movwf	INTCON

	movlw	b'00100000'
	movwf	PIE1
	
	movlw 0x30
	movwf FSR
Ag
	BANKSEL SPBRG
	movlw D'64'
	movwf SPBRG
	BANKSEL TXSTA
	bsf TXSTA,BRGH 	
	
	BANKSEL RCSTA
	movlw b'10010000'
	movwf RCSTA
	
			BANKSEL PIR1
WaitRX		btfss	PIR1,RCIF
			goto	WaitRX	
			call	RC
			goto	WaitRX	

RC
	bcf PIR1,RCIF
	BANKSEL	RCREG
	movf	RCREG,W
	movwf	INDF

	BANKSEL PORTB
	bsf 	PORTB,0 	
	call	t500m
	bcf		PORTB,0
	incf FSR,f
	return 
	

	

delay
t1m 
	movlw d'2'
	movwf cnt1m
tm1lp2	movlw d'249'
	movwf cnt500u
tm1lp1	nop
	nop
	decfsz cnt500u,f
	goto tm1lp1 
	decfsz cnt1m,f
	goto tm1lp2
	return

t100m
	movlw d'100'
	movwf cnt100m
tm2lp	call t1m
	decfsz cnt100m,f
	goto tm2lp
	return

t500m
	movlw d'5'
	movwf cnt500m
tm3lp	call t100m
	decfsz cnt500m,f
	goto tm3lp
	return

t1s
	movlw d'2'
	movwf cnt1s
tm4lp	call t500m
	decfsz cnt1s,f
	goto tm4lp
	return	

t15s
	movlw d'15'
	movwf cnt15s
tm5lp	call t1s
	decfsz cnt15s,f
	goto tm5lp
	return


	END                       ; directive 'end of program'
 
How long is the LED pin staying lit in the simulator? Use MPLAB's stopwatch.

I don't know what speed you're transmitting at, but 9600 baud is 960 bytes per second. The human eye can't distinguish anything over 60 times per second.

Mike
 
upand_at_them said:
How long is the LED pin staying lit in the simulator? Use MPLAB's stopwatch.

I don't know what speed you're transmitting at, but 9600 baud is 960 bytes per second. The human eye can't distinguish anything over 60 times per second.

Mike

I'm trasmitting at 9600 bps. I using Oshon Simulr...but anyway the LED is up for a few microsecs..I acutally knew that it would be tough to distinguish the on-off, but I expected that if the LED blinks..I should retain the 'on' image..as the intensity would persist. But the LED appears to remain off all the while...
 
Electrix said:
upand_at_them said:
How long is the LED pin staying lit in the simulator? Use MPLAB's stopwatch.

I don't know what speed you're transmitting at, but 9600 baud is 960 bytes per second. The human eye can't distinguish anything over 60 times per second.

Mike

I'm trasmitting at 9600 bps. I using Oshon Simulr...but anyway the LED is up for a few microsecs..I acutally knew that it would be tough to distinguish the on-off, but I expected that if the LED blinks..I should retain the 'on' image..as the intensity would persist. But the LED appears to remain off all the while...

It's far too short for you to see, alter your receive routine so it says on much longer (200mS upwards would be good), or even permanently for test purposes.
 
Nigel Goodwin said:
Electrix said:
upand_at_them said:
How long is the LED pin staying lit in the simulator? Use MPLAB's stopwatch.

I don't know what speed you're transmitting at, but 9600 baud is 960 bytes per second. The human eye can't distinguish anything over 60 times per second.

Mike

I'm trasmitting at 9600 bps. I using Oshon Simulr...but anyway the LED is up for a few microsecs..I acutally knew that it would be tough to distinguish the on-off, but I expected that if the LED blinks..I should retain the 'on' image..as the intensity would persist. But the LED appears to remain off all the while...

It's far too short for you to see, alter your receive routine so it says on much longer (200mS upwards would be good), or even permanently for test purposes.

Right, I tried giving it a 1 second timer between the on-off., the LED still remains off all the while. Another thing I just noticed...when I power it on the first time..the LED stays on(confirming that data received) for a second..after that it continously remains off.
 
Here's the code for the transmitter part:

Code:
		list p=16f73		;list directive to define processor
		#include <p16f73.inc>	;processor specific definitions
		errorlevel -302		;suppress "not in bank 0" message

		__CONFIG _CP_OFF 
;Variables decleration

DataByte equ 0x21


;This code executes when a reset occurs.

		ORG     0x000		;place code at reset vector

ResetCode:	clrf    PCLATH		;select program memory page 0
  		goto    Main		;go to beginning of program

Main
;Loading DataByte
movlw 0x41
movwf DataByte

Again
BANKSEL SPBRG
movlw D'25'
movwf SPBRG
BANKSEL TXSTA
bsf TXSTA,BRGH
BANKSEL SPBRG
movlw D'25'
movwf SPBRG
BANKSEL TXSTA
bsf TXSTA,BRGH

BANKSEL TXSTA
movlw B'00100100'
movwf TXSTA
BANKSEL RCSTA
movlw B'10010000'
movwf RCSTA
BANKSEL TXSTA
movlw B'00100100'
movwf TXSTA
BANKSEL RCSTA
movlw B'10010000'
movwf RCSTA

BANKSEL PIR1
WaitTX: btfss PIR1,TXIF
goto WaitTX
BANKSEL PIR1


BANKSEL DataByte
movf DataByte,W
BANKSEL TXREG
movwf TXREG
incf DataByte
goto Again
end
 
Ok..I seem to have figured out what went wrong...

I turned the WDT ON and did not reset the WDT in my program.. :oops:
No wonder the program reset itself before it could reach the LED blink section..

This one adds to my 'remeber to do' list.... :lol:

Dont look at the config settings in my code..i changed them during programming
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top