zipius
Newbie level 5
hi,
i'm making my first pic project, with a 12c508a, very simple project wich is:
press a button (in GP3) toogle a led (GP0) while button is pressed and switch on another led on GP4, and when i press GP3 again the toogle the GP1 led also while the button is pressed and turn off GP4 led. the objective is turn on and off a device with 2 buttons with a single button.
the problem is the project doesn't work properly. maybe i can get some help here.
here's the code:
sorry for bad english in program wich is written in portuguese.
hope someone can help me.
i'm making my first pic project, with a 12c508a, very simple project wich is:
press a button (in GP3) toogle a led (GP0) while button is pressed and switch on another led on GP4, and when i press GP3 again the toogle the GP1 led also while the button is pressed and turn off GP4 led. the objective is turn on and off a device with 2 buttons with a single button.
the problem is the project doesn't work properly. maybe i can get some help here.
here's the code:
Code ASM - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 list p=12c508a #include <p12c508a.inc> ;*******CONFIG******** __CONFIG _MCLRE_OFF & _CP_OFF & _WDT_OFF & _IntRC_OSC ;*******variables******** TEMP_VAR UDATA 0x07 sGPIO RES 1; shadow copy of GPIO db_cnt RES 1; debounce counter dc1 RES 1; delay counter on RES 1; system on flag ;*******RC cal******* RCCAL CODE 0x1FF; vector reset processor RES 1; ;*******VECTOR RESET******* RESET CODE 0x000; effective reset vector movwf OSCCAL; factory osc cal ;*******MAIN PROGRAM******* ;*******INIT******* ini clrf GPIO; clean out clrf sGPIO; actualizar shadow reg movlw b'110100'; config GP0 GP1 GP4 as outputs, GP3 as in tris GPIO; movlw b'1011111'; config internal pull-ups ON option; ;*******PROGRAMA******* main clrf on; clrf dc1; clrf db_cnt; ;wait button press db_dn movlw .26; max count = 20ms/768us = 26 movwf db_cnt; clrf dc1; dn_dly incfsz dc1, f; delay 256x3 = 768us goto dn_dly; btfsc GPIO, 3; if button not press (GP3=1) goto db_dn; reset cont decfsz db_cnt, f; else repeat to archieve max count goto dn_dly; ;OUTS btfss on, 0; test if flag ON/OFF is active goto liga; goto desliga; ;OUT "ON" (GP0) liga movf sGPIO, w; xorlw b'001001'; activate bit GP0 (saida on) and GP4 (led) movwf sGPIO; on shadow reg movwf GPIO; bsf on, 0; activate flag ON/OFF goto db_up; desliga movf sGPIO, w; xorlw b'001010'; activate bit GP1 (out off) and turn GP4 led off movwf sGPIO; movwf GPIO; bcf on, 0; deactivate flag ON/OFF ;wait for button release db_up movlw .26; max count = 20ms/768us = 26 movwf db_cnt; clrf dc1; up_dly incfsz dc1, f; delay 256x3 = 768us goto up_dly; btfss GPIO, 3; if boton is pressed (GP3=0) goto db_up; restart count decfsz db_cnt, f; else repeat until max count is reached goto up_dly; ;update outs btfsc on, 0; test flag ON/OFF to know wich bit is on goto desliga_out; goto liga_out; ;clean out GP0 or GP1 desliga_out movf sGPIO, w; xorlw b'000010'; movwf sGPIO; movwf GPIO; goto db_dn; liga_out movf sGPIO, w; xorlw b'000001'; movwf sGPIO; movwf GPIO; goto db_dn; END
sorry for bad english in program wich is written in portuguese.
hope someone can help me.
Last edited by a moderator: