Continue to Site

# 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

hi,

#### Attachments

• AAesp07.gif
9.9 KB · Views: 230
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
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. )

#### Nigel Goodwin

##### Super Moderator
I tried to get hold of a 84, but they were just to expensive, so I brought a 16F628A.

So you should - check my tutorials which use the 628 instead of the long obselete 84.

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

Last edited:

#### Nigel Goodwin

##### Super Moderator

It's Jitsu (art) from Ju Jitsu (gentle art), which I teach.

#### Pommie

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

Mike.

#### Nigel Goodwin

##### Super Moderator
In your code you should change cblock to cblock 0x20 or you will have problems when you add more variables.

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.

#### 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???

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

Last edited:

#### Pommie

##### Well-Known Member
The error given by MPLAB is,

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

Mike.

#### Nigel Goodwin

##### Super Moderator
The error given by MPLAB is,

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

Mike.

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

#### Pommie

##### Well-Known Member

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

Except for the OP.

Mike.

#### Nigel Goodwin

##### Super Moderator
Except for the OP.

Yes, and many people don't bother using an ORG to set the beginning, or don't add an end to finish the program, and if they do they expect the 'end' to prevent the program runing on.

#### 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,

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 ?

#### Nigel Goodwin

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

I would have thought so, why wouldn't you?.

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

Replies
90
Views
5K
Replies
10
Views
968
Replies
8
Views
1K
Replies
37
Views
2K
Replies
4
Views
2K