![]() | ![]() | ![]() |
| |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
| | Tools |
| | #1 |
|
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 | |
| |
| | #2 | |
| Quote:
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! | ||
| |
| | #3 |
|
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 :?:
| |
| |
| | #4 |
|
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! | |
| |
| | #5 |
|
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:
| |
| |
| | #6 | |
| Quote:
__________________ "I share, thus I am" Jay.slovak Read this! ICD2 Clone Best PIC/DsPIC Bootloader Read my Inchworm ICD2 review! | ||
| |
| | #7 | |
| Quote:
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. | ||
| |
| | #8 |
|
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! | |
| |
| | #9 |
|
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
Code: loop:
movf COUNT,0
; <--------------------interrupt here
movwf PORTA
goto loop
__________________ "Having to do with Motion Control" | |
| |
|
| Tags |
| code |
| Thread Tools | |
| Display Modes | |
| |