Dear experts,
I am new to this programing. I have a small project which i would like to get help with. Its a small car which should turn ON the lights and turn OFF with two buttons.
Please help me.
Thanks
Dear experts,
I am new to this programing. I have a small project which i would like to get help with. Its a small car which should turn ON the lights and turn OFF with two buttons.
Please help me.
Thanks
Hi and welcome.
try the following
Code:' ' Pic Configuration ' ================= ASM IFNDEF PM_USED list w=-207 ; Program Configuration Register 1 cfg1 = _INTRC_IO & _WDT_OFF & _PWRTE_ON & _MCLR_OFF & _BODEN_ON & _LVP_OFF & _CCP1_RB0 cfg2 = _CP_OFF & _CPD_OFF & _WRT_PROTECT_OFF & _DEBUG_OFF __CONFIG _CONFIG1, cfg1 & cfg2 ; Program Configuration Register 2 __CONFIG _CONFIG2, _IESO_OFF & _FCMEN_OFF list w=+207 ELSE device INTRC_OSC_NOCLKOUT, WDT_OFF, PWRT_ON, MCLR_OFF, BOD_ON, LVP_OFF, CCPMX_OFF device PROTECT_OFF, CPD_OFF, WRT_OFF, DEBUG_OFF device2 FCMEN_OFF, IESO_OFF ENDIF ENDASM OSCCON = %01100000 ' set to 4 MHz clock ' ' Hardware configuration ' ====================== TRISB=0 ' Set all PORTB pins to output TRISA=255 ' Set all PORTA pins to output ANSEL = 0 ' disable adc converters CMCON=7 ' disable analog comparator ' ' Hardware assignment ' =================== ' ' Push buttons ' ------------ ' Push buttons are connected between PIC i/o and gnd ' don't forget to add a pull-up resistor on the i/o too ' ONButton VAR PORTA.0 OFFButton VAR PORTA.1 ' ' Light ' ----- ' LED connect between I/O and gnd... with a resistor in serie ' LIGHT VAR PORTB.0 ' ' Hardware initialisation ' ======================= WHILE OSCCON.2=0 : WEND ' wait 'till internal OSC is stable PORTB=0 ' clear all PORTB i/o START: if ONButton = 0 then light = 1 ' turn the LED on endif if offbutton = 0 then light = 0 ' turn the led off endif GOTO START
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
thanks a lot, question! the above configs. can be done in the software as well right so i dont need to do those in the coding??
yes you can do it in your programmer software as well... but you need to set them each time... and remind which one you need to set. Kinda annoying if months/years later you need to reprogram a PIC and you don't remind them.
Once you load the .HEX file to program your PIC, your PIC Programmer software have to be smart enough to refresh the default one and to program them. Careful, some software need to be warned to do so.
I ALWAYS set them in code, it's the right place to fit them.. not in a README.TXT or on a piece of paper sticked somewhere.
But it's me
EDIT: the above are way to much, but as i didn't know which assembler you're using (PM/MPASM) i've just put both and let the compiler choose for you. See the FAQ for more details.
Last edited by mister_e; - 18th November 2007 at 11:08.
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
thanks a lot, I will try it out and let you know. another thing forgot to ask. will it work for 4 LEDs or two? e.g. two front two rear...
.....................
Last edited by nonny; - 20th November 2007 at 14:15.
Bookmarks