I have been playing around with this smaller pic that I got but it is still confusing the crap out of me. What I'm trying to do now is get it so when I press a switch on I/O port 1 it will light up an led on I/O port 0. Here is the code that I have so far. It kind of sort of almost works. If there is any thing else that you see that I am doing wrong please let me know. PHP: processor 12F629 radix DEC ORG 0x0000 DATA 0184H Carry EQU 0 Zero_ EQU 2 RP0 EQU 5 GPIO EQU 0x05 ;Defines the register for GPIO TRISIO EQU 0x85 ;Defines the register for TRISIO CM0 EQU 0 CM1 EQU 1 CM2 EQU 2 x EQU 0x20 y EQU 0x22 MOVLW 0x00 BCF 0x03,RP0 MOVWF GPIO BSF 0x03,RP0 CLRF TRISIO BCF 0x03,RP0 BSF 0x19,CM2 BSF 0x19,CM1 BSF 0x19,CM0 CLRF GPIO MOVLW 0x02 ;Sets all pins to input exept I/O 1 MOVWF TRISIO GOTO main main BTFSC GPIO,0x01 BCF GPIO,0x00 BSF GPIO,0x00 GOTO main END
Try this code: Code: list p=12F629 ; list directive to define processor #include <p12F629.inc> ; processor specific variable definitions __CONFIG _CP_OFF & _CPD_OFF & _BODEN_ON & _MCLRE_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT ;----VARIABLES HERE----- CBLOCK 0X20 ;PUT YOUR VARIABLES HERE ENDC ;----------------------- ORG 0X000 CALL INIT GOTO MAIN 0RG 0X004 RETFIE INIT CLRF GPIO MOVLW B'00000111' ;TURN OFF COMPARATOR MOVWF CMCON BSF STATUS,RP0 MOVLW B'00000010' ;SET ALL PINS TO OUTPUT EXCEPT GPIO,1 MOVWF TRISIO BCF STATUS,RP0 RETURN MAIN BTFSS GPIO,1 ;GPIO,0 HIGH WHILE GPIO,1 INPUT IS HIGH BCF GPIO,0 BTFSC GPIO,1 BSF GPIO,0 GOTO MAIN END Notes on your code: I suggest you change your default radix to hex. Lines like: BSF GPIO,0x00 Your addressing bits when using BSF, BCF etc, so don't put a hex number as the argument. You're setting up TRISIO while in Bank 0, but TRISIO is in Bank 1. Your switch routine is a bit dodgy - your output will always light up an LED, only in pressing the switch will change between on and partly on.
Well that code dose work alot better than the code I posted. It still keeps the led lit untell I/O 1 gose high. EDIT: I don't see where you are sending 0x01 to GPIO to make I/O 0 high?
"0x01 to GPIO to make I/O 0 high" doesn't make sense - BCF and BSF mean Bit Clear File and Bit Set File respectively. You're only addressing one bit of the register, so for example BSF GPIO,4 turns on bit 4 of GPIO. (no hex values anywhere!)
yep at last as far as I know it is. Below is all I have hooked up sence I'm using internal osc. +5v to Vdd (pin 1) and ground to Vss (Pin 8) Led is hooked from pin 7 (GP0) to ground Switch is between Pin 6 (GP1) to ground EDIT: I forgot to say I'm compiling with mplab and then burning with IC-Prog 1.05D. The hardware programer is an PG2C from sparkfun.
Where would the pull up resistor go? Between the out put pin and the led? Or are you talking about puting it between the input ping and the switch?
Thanks I will give this a try when I get home from work. I did do some reading on the pull up and pull down resisters. From what I read I may need to do this. +5V to switch to GP1 GP1 to 10k resister to ground This will pull the pin low when the switch is off and then make the pin go high when I push the button right?
Yes, you had it the wrong way round. You were pulling the pin low when pressing the switch so it was doing the opposite of what it should be doing. A 10k to ground would do, or you can leave the switch as it is, change the BSF and BCF round in the code and turn on weak pullups (WPU) on the PIC.
Any chance you know off hand how to turn the week pull ups on in the code? I figured at first that switching those two commands would fix it but little did I know that the pin was floating.
if you look up the datasheet for the pic, you see on page 22, there is the WPU, Weak Pull-Up register, it controls the invidual pins pull up settings, but you must enable them all by setting GPPU bit in the OPTION_REG word.
Ahh I saw the WPU register but I missed the GPPU bit. Any way I decided not to go with the WPU register because using a pull down resister seems more logical to me. GP1 = 0 then GP0 = 0 GP1 = 1 then GP0 = 1 If I used the WPU it would be like this. GP1 = 1 then GP0 = 0 GP1 = 0 then GP0 = 1 I don't know the first set just seems much more logical to me. I guess that is programers preference. I'm planing on writing a basic intro to electronics that I already know about.