Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 24th April 2005, 02:16 PM   #1
Default code help

my code doesn't do what it is supposed to do.the program is for the pic to increment for every closing of the switch(5 volts input to rb0). it just continuously count up to 9 and then back to zero(binary). can someone help me wiht this code or schematic? here's the code
Code:
PROCESSOR	16f84a
#include "P16f84a.inc"

org 0x00
COUNT	EQU 0X0c
TEMP	EQU 0X0d
goto	main

org	0x04
movwf	TEMP
incf	COUNT,1
movlw	0x0a
subwf	COUNT,0
btfss	STATUS,0
goto	carry_on
goto	clear
carry_on
bcf	INTCON,0X01
movlw	TEMP
retfie
clear
clrf	COUNT
bcf	INTCON,1
retfie

main
bsf	INTCON,7
bsf	INTCON,4
bsf	INTCON,1
bsf	STATUS,5
movlw	0X01
movwf	TRISB
movlw	0X10
movwf	TRISA
bcf	STATUS,5
loop
movf	COUNT,0
movwf	PORTA
goto	loop
end
and here's the schematic:
Attached Thumbnails
code help-7segcount.gif  
gastonanthony is offline  
Old 24th April 2005, 02:34 PM   #2
Default Re: code help

Quote:
Originally Posted by gastonanthony
my code doesn't do what it is supposed to do.the program is for the pic to increment for every closing of the switch(5 volts input to rb0). it just continuously count up to 9 and then back to zero(binary). can someone help me wiht this code or schematic? here's the code
Code:
PROCESSOR	16f84a
#include "P16f84a.inc"

org 0x00
COUNT	EQU 0X0c
TEMP	EQU 0X0d
goto	main

org	0x04
movwf	TEMP
incf	COUNT,1
movlw	0x0a
subwf	COUNT,0
btfss	STATUS,0
goto	carry_on
goto	clear
carry_on
bcf	INTCON,0X01
movlw	TEMP
retfie
clear
clrf	COUNT
bcf	INTCON,1
retfie

main
bsf	INTCON,7
bsf	INTCON,4
bsf	INTCON,1
bsf	STATUS,5
movlw	0X01
movwf	TRISB
movlw	0X10
movwf	TRISA
bcf	STATUS,5
loop
movf	COUNT,0
movwf	PORTA
goto	loop
end
and here's the schematic:
And ER oscilator mode is not the best solution...
Don't put MCLR HIGH without resistor!
Where are LEDs current limiting resistors???
__________________
"I share, thus I am"
Jay.slovak
Read this!
ICD2 Clone
Best PIC/DsPIC Bootloader

Read my Inchworm ICD2 review!
Jay.slovak is offline  
Old 24th April 2005, 02:57 PM   #3
Default

hehe ops: sorry, i forgot about the current limiting resistors, i got this schematic and code from a pdf tutorial file. i already modified the clock by connecting a capacitor at pin 16 and ground(to make an RC network) but the circuit still counts upto 9 automatically and doesn't respond to the switch :?:
gastonanthony is offline  
Old 24th April 2005, 03:01 PM   #4
Default

Did you disable the WDT?
Insert this into your source code:
Code:
	list	p=16F84A
	#include	<p16F84A.inc>
	__CONFIG	_CP_OFF & _WDT_OFF & _PWRTE_ON &_RC_OSC
__________________
"I share, thus I am"
Jay.slovak
Read this!
ICD2 Clone
Best PIC/DsPIC Bootloader

Read my Inchworm ICD2 review!
Jay.slovak is offline  
Old 24th April 2005, 03:02 PM   #5
Default

why does the mclr need a resistor?for current limiting?i thought it is ok to connect it directly to 5V because the tutorial does this for all of it's circuits ops:
gastonanthony is offline  
Old 24th April 2005, 03:05 PM   #6
Default

Quote:
Originally Posted by gastonanthony
why does the mclr need a resistor?for current limiting?i thought it is ok to connect it directly to 5V because the tutorial does this for all of it's circuits ops:
It's a good pracise to put it there. Microchip strongly recomend to put it there to avoid Latch-up current...
__________________
"I share, thus I am"
Jay.slovak
Read this!
ICD2 Clone
Best PIC/DsPIC Bootloader

Read my Inchworm ICD2 review!
Jay.slovak is offline  
Old 24th April 2005, 03:13 PM   #7
Default

Quote:
Originally Posted by gastonanthony
why does the mclr need a resistor?for current limiting?i thought it is ok to connect it directly to 5V because the tutorial does this for all of it's circuits ops:
It's fine to directly connect it to 5V, the only real reason to use a resistor is as a pull-up for a reset switch down to 0V.

One advantage of using the 16F628, rather than the obselete 84, is that you can switch MCLR to be an extra I/O pin, which then internally connects MCLR to 5V.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 24th April 2005, 03:31 PM   #8
Default

I take it as a good practice, because sometimes when I want to reset the PIC which doesn't have a MCLR button to GND, I can't do it if there is no resistor between VDD and MCLR.

And Yes, use 16F628 instead 84. 628 is cheaper and has more peripherals... (internal 4Mhz oscilator...)
__________________
"I share, thus I am"
Jay.slovak
Read this!
ICD2 Clone
Best PIC/DsPIC Bootloader

Read my Inchworm ICD2 review!
Jay.slovak is offline  
Old 24th April 2005, 05:10 PM   #9
Default

You failed to restore the W register correctly in the interrupt service routine.

The correct code in the interrupt service routine should be as follows:

Code:
    movf   TEMP,W 
    retfie
If an interrupt in the main loop occurs between the two instruction steps:

Code:
loop:
    movf   COUNT,0 
; <--------------------interrupt here
    movwf   PORTA 
    goto   loop
The last value of the W in the interrupt sevice routine will be written to PORTA.
__________________
"Having to do with Motion Control"
motion is offline  
Reply

Tags
code

Thread Tools
Display Modes




All times are GMT. The time now is 12:26 PM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker