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.

PIC IOC issues

Status
Not open for further replies.
hmmm..that might be important lol. TY now it works perfectly, just gotta adjust the PS for TMR2 and maybe reorganize the code. It is not very efficient right now.
 
Last edited:
Changing banks by doing this:
Code:
	movlw	b'00111000'
	movwf	STATUS			;BANK 1
	movlw	b'01000001'
	movwf	OSCCON			;sets oscillator to 1MHz
is not the best way. One, it's not as clear what you're doing as it could be. Two, wiping out the STATUS register every time you change banks could conceivably cause some serious bugs under the right circumstances. I'd think ORing or BSF/BCFing those bits in there would be safer.

Why not use the banksel directive? Like this:
Code:
	banksel	OSCCON		;bank 1
	movlw	b'01000001'
	movwf	OSCCON		;sets oscillator to 1MHz
Let the assembler do the work for ya. Makes the code nice and readable. And it isn't as prone to operator error as diddling the bits yourself.
 
Last edited:
True. And the code would be a little more portable for different 16f's too. I already have it posted in the projects forum, I will mod the code there.
 
Here's another thing you're doing that could (should?) be done differently. Your code has this
Code:
w_temp		EQU	0x40	; variable used for context saving
status_temp	EQU	0x41	; variable used for context saving
pclath_temp	EQU	0x22	; variable used for context saving
Digit1		EQU	0x43
Digit2		EQU	0x44
temp		EQU	0x45
Curious why you're starting your variables at $40 instead of the start of RAM, $20. Datasheet page 31. One is at $22 but the rest are in the $40's.

Why not use a cblock instead? Easier to type. Easier to read.
Code:
	cblock	0x20
	w_temp,status_temp,pclath_temp,Digit1,Digit2,temp
	endc
If you have many variables you can do multiple lines like this (Note, no comma at end of lines):
Code:
	cblock	0x20
	w_temp,status_temp,pclath_temp
	Digit1,Digit2,temp
	endc
Or if you have only a few and want them one per line you can do this:
Code:
	cblock	0x20
	w_temp
	status_temp
	pclath_temp
	endc
 
Last edited:
When using cblock you can also set the variable size,
Code:
	cblock 0x20
Accumulator:2
CharBuffer:8
TimeBuffer:0
Seconds
Minutes
Hours
;etc
	endc
In the above TimeBuffer and Seconds would both be 0x2a.

Mike.
 
Thanks guys. When I was starting out programming I avoided using cblock and banksel and others like it. I felt that I should do things manually so that I understood everything that was happening. But now I guess I should start using them.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top