• 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.

16F628A Code Problem

Status
Not open for further replies.

Number17

New Member
Hi

I've started using my pics today again, after about 2 months. I've compiled a small program just to refresh my memory again. Its a simple flashing led. It works fine, but when I add the command BTFSS it seems that the pic gets stuck there. No matter what I do, I can't get the pic to read the status on a port. The pic react as if the switch is open. I've added a 10k from the supply to RA0, and the switch from RA0 to ground.

Any help would be great

Here's the code

Code:
; INCLUDE PIC16F628A

LIST 		P=16F628A
INCLUDE 	<P16F628A.INC>
__CONFIG	_BODEN_OFF&_CP_OFF&_PWRTE_OFF&_WDT_OFF&_XT_OSC&_LVP_OFF&_MCLRE_OFF
ERRORLEVEL	-302
ERRORLEVEL	-203

; GENERAL REGISTERS

CBLOCK

COUNT1
COUNT2

ENDC

; SETUP THE I/O PORTS ETC

BSF		STATUS,5H
MOVLW	B'01'
MOVWF	TRISA
BCF		STATUS,5H
CLRF	PORTA

; START

START

BTFSS	PORTA,0
GOTO	START

BSF		PORTA,1
CALL	DELAY

BCF		PORTA,1
CALL	DELAY

GOTO	START

; SUBROUTINES

DELAY	DECFSZ	COUNT1
		GOTO	DELAY
		DECFSZ	COUNT2
		GOTO	DELAY
RETURN

END
 

ericgibbs

Well-Known Member
Most Helpful Member
hi,

You have set AN0 as an analog input.:)
 

Attachments

Last edited:

Number17

New Member
Hi

Thanks I forgot about the comparators. I've added these 2 lines before the setup of the I/O according to the datasheet.

Code:
MOVLW	0X07
MOVWF	CMCON
Now its works perfect.

What I don't understand though, is that I never really added those lines to the program before, yet it still worked most times.
 

ericgibbs

Well-Known Member
Most Helpful Member
Hi

Thanks I forgot about the comparators. I've added these 2 lines before the setup of the I/O according to the datasheet.

Code:
MOVLW	0X07
MOVWF	CMCON
Now its works perfect.

What I don't understand though, is that I never really added those lines to the program before, yet it still worked most times.
hi,
Did you always use AN0 or another ANx.?

Which part of RSA are you from.?
 

Number17

New Member
Hi

Did you always use AN0 or another ANx.?
No, I'm still a noob. I learned from a tutorial that used a 16F84, so there were no analog pins. I had to read the datasheet about the comparators. I tried to get hold of a 84, but they were just to expensive, so I brought a 16F628A.

Which part of RSA are you from.?
I was born in the Freestate, but now I live in Guateng. ( This is also why my english is bad, because my home language is Afrikaans. )
 

Number17

New Member
So you should - check my tutorials which use the 628 instead of the long obselete 84.
When I first started, I didn't know of your tutorials. In the time passed I saw them, but I never really looked at it. I'll check them out.

Thanks.

Just something quick, what does that sign in your avatar mean?
 
Last edited:

Pommie

Well-Known Member
Most Helpful Member
In your code you should change cblock to cblock 0x20 or you will have problems when you add more variables.

Mike.
 

geko

Active Member
Hi Mike,

So what actually happens if you use cblock on it's own?, I've never considered doing it, or thought anyone ever would.

cblock [expr] label[:increment][,label[:increment]]endc
expr indicates the starting value for the first name in the block. If no expression is found, the first name will receive a value one higher than the final name in the previous cblock. If the first cblock in the source file has no expr, assigned values start with zero.
 

Mr RB

Well-Known Member
I believe it defaults to 0x00, so the 2 registers he was writing to are INDF and TMR0... Kinda scary. :)

Hey Nigel, if your avatar is "art" and not "gentle art"... Does that mean you are into the NOT-gentle form of Ju Jitsu??? :eek: :D

(edit) Darn gazumped by geko in <60 seconds... :(
 
Last edited:

Pommie

Well-Known Member
Most Helpful Member
The error given by MPLAB is,

Message[313] : CBLOCK constants will start with a value of 0.

So basically your variables will occupy the same area as INDF, TMR0, PCL etc.

Mike.
 

Nigel Goodwin

Super Moderator
Most Helpful Member
The error given by MPLAB is,

Message[313] : CBLOCK constants will start with a value of 0.

So basically your variables will occupy the same area as INDF, TMR0, PCL etc.

Mike.
Bad news :D

Like I said, it's not something I would ever have thought of doing, and can't concieve of anyone else doing so.
 

mvs sarma

Well-Known Member
even the code is not formatted properly, and perhaps has to look like this
Code:
; INCLUDE PIC16F628A

	LIST 		P=16F628A
	INCLUDE 	<P16F628A.INC>
	__CONFIG	_BODEN_OFF&_CP_OFF&_PWRTE_OFF&_WDT_OFF&_XT_OSC&_LVP_OFF&_MCLRE_OFF
	ERRORLEVEL	-302
	ERRORLEVEL	-203

; GENERAL REGISTERS

	CBLOCK 0x20

COUNT1
COUNT2

	ENDC

; SETUP THE I/O PORTS ETC

	BSF		STATUS,RP0
	MOVLW	0x01
	MOVWF	TRISA
	BCF		STATUS,RP0
	CLRF	PORTA

        ORG         0x00
; START

START

	BTFSS	PORTA,0
	GOTO	START

	BSF		PORTA,1
	CALL	DELAY

	BCF		PORTA,1
	CALL	DELAY

	GOTO	START

; SUBROUTINES

DELAY	DECFSZ	COUNT1,F
		GOTO	DELAY
		DECFSZ	COUNT2,F
		GOTO	DELAY
	RETURN

	END
 

mvs sarma

Well-Known Member
The error given by MPLAB is,

Message[313] : CBLOCK constants will start with a value of 0.

So basically your variables will occupy the same area as INDF, TMR0, PCL etc.

Mike.
Once we defined Include file, the CBLOC should be started properly< I thought . Should we define it, still ?
 

mvs sarma

Well-Known Member
I would have thought so, why wouldn't you?.
I have followed your earlier comments and added that CBLOC starting address. At that moment , what was important for me was to indicate the OP that he did not have proper format. thus my doubt still remains, whether the include would not take care of start of user definitions? and whether the user still needs to provide the CBLOC start point ( as this is controller dependent).
 
Last edited:
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top