Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Warning[215] C:\NEW\MYFIRST.ASM 2 : Processor superceded by command line. Verify processor symbol.
Error[105] C:\NEW\MYFIRST.ASM 3 : Cannot open file (Include File "P16F628.inc" not found)
Error[113] C:\NEW\MYFIRST.ASM 10 : Symbol not previously defined (CMCON)
Error[113] C:\NEW\MYFIRST.ASM 12 : Symbol not previously defined (STATUS)
Error[113] C:\NEW\MYFIRST.ASM 12 : Symbol not previously defined (RP0)
Error[113] C:\NEW\MYFIRST.ASM 14 : Symbol not previously defined (TRISB)
Error[113] C:\NEW\MYFIRST.ASM 15 : Symbol not previously defined (TRISA)
Error[113] C:\NEW\MYFIRST.ASM 16 : Symbol not previously defined (STATUS)
Error[113] C:\NEW\MYFIRST.ASM 16 : Symbol not previously defined (RP0)
Error[113] C:\NEW\MYFIRST.ASM 20 : Symbol not previously defined (PORTA)
Error[113] C:\NEW\MYFIRST.ASM 21 : Symbol not previously defined (PORTB)
Error[113] C:\NEW\MYFIRST.ASM 25 : Symbol not previously defined (PORTA)
Error[113] C:\NEW\MYFIRST.ASM 26 : Symbol not previously defined (PORTB)
Ricardoco said:now i will have to wait to see what williB has planned for me lol and what this piece of code does unless you have an idea???
NOLIST
#include "C:\DOCUME~1\ADMINI~1\Desktop\3_BUTT~2.PBP"
LIST
BO Equ 41
BOH Equ 42
BOHH Equ 43
BOHHH Equ 44
F1_SOF equ $ ; 3_BUTT~2.BAS
F1_000004 equ $ ; in [3_BUTT~2.BAS] ALL_DIGITAL = TRUE
Movlw 7
Movwf CMCON
F1_000005 equ $ ; in [3_BUTT~2.BAS] bo = 0 ' give variable initial value
Clrf BOHHH
Clrf BOHH
Clrf BOH
Clrf BO
F1_000006 equ $ ; in [3_BUTT~2.BAS] TRISB = 0 ' Set PORTB (LEDs) to all output
Bsf STATUS,5
ram_bank = 1
Clrf TRISB
F1_000007 equ $ ; in [3_BUTT~2.BAS] PORTB = 0 ' All LEDs off
Bcf STATUS,5
ram_bank = 0
Clrf PORTB
LOOP
F1_000009 equ $ ; in [3_BUTT~2.BAS] PORTA = 0 ' PORTA lines low to read buttons
Clrf PORTA
F1_000010 equ $ ; in [3_BUTT~2.BAS] TRISA = $F0 ' Enable all buttons
Movlw 240
Bsf STATUS,5
ram_bank = 1
Movwf TRISA
F1_000011 equ $ ; in [3_BUTT~2.BAS] If PORTA.0 = 1 Then ' If 4th button pressed...
Bcf STATUS,5
ram_bank = 0
Btfss PORTA,0
Goto bc@ll2
F1_000012 equ $ ; in [3_BUTT~2.BAS] bo = bo +1 ' add 1 to count variable
Movlw 1
Addwf BO,F
Clrw
Btfsc STATUS,0
Movlw 1
Addwf BOH,F
Clrw
Btfsc STATUS,0
Movlw 1
Addwf BOHH,F
Clrw
Btfsc STATUS,0
Movlw 1
Addwf BOHHH,F
F1_000013 equ $ ; in [3_BUTT~2.BAS] delayms 100
Movlw 100
Call dl@ms
F1_000014 equ $ ; in [3_BUTT~2.BAS] endif
bc@ll2
F1_000015 equ $ ; in [3_BUTT~2.BAS] if bo > 6 then
Clrf PP2HHH
Clrf PP2HH
Clrf PP2H
Movlw 6
Movwf PP2
Movfw PP2HHH
Xorlw 128
Movwf PP4
Movfw BOHHH
Xorlw 128
Subwf PP4,W
Btfss STATUS,2
Goto cp@lb2
Movfw BOHH
Subwf PP2HH,W
Btfss STATUS,2
Goto cp@lb2
Movfw BOH
Subwf PP2H,W
Btfss STATUS,2
Goto cp@lb2
Movfw BO
Subwf PP2,W
cp@lb2
Btfsc STATUS,0
Goto bc@ll4
F1_000016 equ $ ; in [3_BUTT~2.BAS] bo = 6
Clrf BOHHH
Clrf BOHH
Clrf BOH
Movlw 6
Movwf BO
F1_000017 equ $ ; in [3_BUTT~2.BAS] Endif
bc@ll4
F1_000018 equ $ ; in [3_BUTT~2.BAS] If PORTA.1 = 1 Then ' If 3rd button pressed...
Btfss PORTA,1
Goto bc@ll6
F1_000019 equ $ ; in [3_BUTT~2.BAS] bo = bo -1
Movlw 1
Subwf BO,F
Clrw
Btfss STATUS,0
Movlw 1
Subwf BOH,F
Clrw
Btfss STATUS,0
Movlw 1
Subwf BOHH,F
Clrw
Btfss STATUS,0
Movlw 1
Subwf BOHHH,F
F1_000020 equ $ ; in [3_BUTT~2.BAS] if bo < 0 then
Clrf PP2HHH
Clrf PP2HH
Clrf PP2H
Clrf PP2
Movfw BOHHH
Xorlw 128
Movwf PP4
Movfw PP2HHH
Xorlw 128
Subwf PP4,W
Btfss STATUS,2
Goto cp@lb3
Movfw PP2HH
Subwf BOHH,W
Btfss STATUS,2
Goto cp@lb3
Movfw PP2H
Subwf BOH,W
Btfss STATUS,2
Goto cp@lb3
Movfw PP2
Subwf BO,W
cp@lb3
Btfsc STATUS,0
Goto bc@ll8
F1_000021 equ $ ; in [3_BUTT~2.BAS] bo = 0
Clrf BOHHH
Clrf BOHH
Clrf BOH
Clrf BO
F1_000022 equ $ ; in [3_BUTT~2.BAS] endif
bc@ll8
F1_000024 equ $ ; in [3_BUTT~2.BAS] endif
bc@ll6
F1_000025 equ $ ; in [3_BUTT~2.BAS] if bo = 0 then
Movfw BOHHH
Iorwf BOHH,W
Iorwf BOH,W
Iorwf BO,W
Btfss STATUS,2
Goto bc@ll10
F1_000026 equ $ ; in [3_BUTT~2.BAS] portb = 0
Clrf PORTB
F1_000027 equ $ ; in [3_BUTT~2.BAS] endif
bc@ll10
F1_000028 equ $ ; in [3_BUTT~2.BAS] if bo = 1 then
Movfw BO
Xorlw 1
Iorwf BOH,W
Iorwf BOHH,W
Iorwf BOHHH,W
Btfss STATUS,2
Goto bc@ll12
F1_000029 equ $ ; in [3_BUTT~2.BAS] portb.0 = 1
Bsf PORTB,0
F1_000030 equ $ ; in [3_BUTT~2.BAS] portb.1 = 0
Bcf PORTB,1
F1_000031 equ $ ; in [3_BUTT~2.BAS] portb.2 = 0
Bcf PORTB,2
F1_000032 equ $ ; in [3_BUTT~2.BAS] portb.3 = 0
Bcf PORTB,3
F1_000033 equ $ ; in [3_BUTT~2.BAS] portb.4 = 0
Bcf PORTB,4
F1_000034 equ $ ; in [3_BUTT~2.BAS] portb.5 = 0
Bcf PORTB,5
F1_000035 equ $ ; in [3_BUTT~2.BAS] end if
bc@ll12
F1_000036 equ $ ; in [3_BUTT~2.BAS] if bo = 2 then
Movfw BO
Xorlw 2
Iorwf BOH,W
Iorwf BOHH,W
Iorwf BOHHH,W
Btfss STATUS,2
Goto bc@ll14
F1_000037 equ $ ; in [3_BUTT~2.BAS] portb.0 = 1
Bsf PORTB,0
F1_000038 equ $ ; in [3_BUTT~2.BAS] portb.1 = 1
Bsf PORTB,1
F1_000039 equ $ ; in [3_BUTT~2.BAS] portb.2 = 0
Bcf PORTB,2
F1_000040 equ $ ; in [3_BUTT~2.BAS] portb.3 = 0
Bcf PORTB,3
F1_000041 equ $ ; in [3_BUTT~2.BAS] portb.4 = 0
Bcf PORTB,4
F1_000042 equ $ ; in [3_BUTT~2.BAS] portb.5 = 0
Bcf PORTB,5
F1_000043 equ $ ; in [3_BUTT~2.BAS] end if
bc@ll14
F1_000044 equ $ ; in [3_BUTT~2.BAS] if bo = 3 then
Movfw BO
Xorlw 3
Iorwf BOH,W
Iorwf BOHH,W
Iorwf BOHHH,W
Btfss STATUS,2
Goto bc@ll16
F1_000045 equ $ ; in [3_BUTT~2.BAS] portb.0 = 1
Bsf PORTB,0
F1_000046 equ $ ; in [3_BUTT~2.BAS] portb.1 = 1
Bsf PORTB,1
F1_000047 equ $ ; in [3_BUTT~2.BAS] portb.2 = 1
Bsf PORTB,2
F1_000048 equ $ ; in [3_BUTT~2.BAS] portb.3 = 0
Bcf PORTB,3
F1_000049 equ $ ; in [3_BUTT~2.BAS] portb.4 = 0
Bcf PORTB,4
F1_000050 equ $ ; in [3_BUTT~2.BAS] portb.5 = 0
Bcf PORTB,5
F1_000051 equ $ ; in [3_BUTT~2.BAS] end if
bc@ll16
F1_000052 equ $ ; in [3_BUTT~2.BAS] if bo = 4 then
Movfw BO
Xorlw 4
Iorwf BOH,W
Iorwf BOHH,W
Iorwf BOHHH,W
Btfss STATUS,2
Goto bc@ll18
F1_000053 equ $ ; in [3_BUTT~2.BAS] portb.0 = 1
Bsf PORTB,0
F1_000054 equ $ ; in [3_BUTT~2.BAS] portb.1 = 1
Bsf PORTB,1
F1_000055 equ $ ; in [3_BUTT~2.BAS] portb.2 = 1
Bsf PORTB,2
F1_000056 equ $ ; in [3_BUTT~2.BAS] portb.3 = 1
Bsf PORTB,3
F1_000057 equ $ ; in [3_BUTT~2.BAS] portb.4 = 0
Bcf PORTB,4
F1_000058 equ $ ; in [3_BUTT~2.BAS] portb.5 = 0
Bcf PORTB,5
F1_000059 equ $ ; in [3_BUTT~2.BAS] endif
bc@ll18
F1_000060 equ $ ; in [3_BUTT~2.BAS] if bo = 5 then
Movfw BO
Xorlw 5
Iorwf BOH,W
Iorwf BOHH,W
Iorwf BOHHH,W
Btfss STATUS,2
Goto bc@ll20
F1_000061 equ $ ; in [3_BUTT~2.BAS] portb.0 = 1
Bsf PORTB,0
F1_000062 equ $ ; in [3_BUTT~2.BAS] portb.1 = 1
Bsf PORTB,1
F1_000063 equ $ ; in [3_BUTT~2.BAS] portb.2 = 1
Bsf PORTB,2
F1_000064 equ $ ; in [3_BUTT~2.BAS] portb.3 = 1
Bsf PORTB,3
F1_000065 equ $ ; in [3_BUTT~2.BAS] portb.4 = 1
Bsf PORTB,4
F1_000066 equ $ ; in [3_BUTT~2.BAS] portb.5 = 0
Bcf PORTB,5
F1_000067 equ $ ; in [3_BUTT~2.BAS] endif
bc@ll20
F1_000068 equ $ ; in [3_BUTT~2.BAS] if bo = 6 then
Movfw BO
Xorlw 6
Iorwf BOH,W
Iorwf BOHH,W
Iorwf BOHHH,W
Btfss STATUS,2
Goto bc@ll22
F1_000069 equ $ ; in [3_BUTT~2.BAS] portb.0 = 1
Bsf PORTB,0
F1_000070 equ $ ; in [3_BUTT~2.BAS] portb.1 = 1
Bsf PORTB,1
F1_000071 equ $ ; in [3_BUTT~2.BAS] portb.2 = 1
Bsf PORTB,2
F1_000072 equ $ ; in [3_BUTT~2.BAS] portb.3 = 1
Bsf PORTB,3
F1_000073 equ $ ; in [3_BUTT~2.BAS] portb.4 = 1
Bsf PORTB,4
F1_000074 equ $ ; in [3_BUTT~2.BAS] portb.5 = 1
Bsf PORTB,5
F1_000075 equ $ ; in [3_BUTT~2.BAS] end if
bc@ll22
F1_000076 equ $ ; in [3_BUTT~2.BAS] delayms 300
Movlw 1
Movwf PP1H
Movlw 44
Call dly@w
F1_000077 equ $ ; in [3_BUTT~2.BAS] Goto Loop ' Do it forever
Goto LOOP
END
DEVICE = 16F84A 'ENTER WHAT DEVICE YOU ARE USING
XTAL = 4 'SAME GOES FOR CRYSTAL
INPUT PORTA 'TELLING THE PIC TO SET PORTA TO INPUT
OUTPUT PORTB 'TELLING THE PIC TO SET PORTB TO OUTPUT
SYMBOL BUTUP = PORTA.0 'DEFINING PORTA.0 TO EQUAL BUTUP
SYMBOL BUTDN = PORTA.1 'DEFINING PORTA.1 TO EQUAL BUTDN
BUTVAL VAR BYTE 'SETTING BUTVAL VARIABLE TO BYTE LENGTH
MAIN:
IF BUTUP = 1 THEN BUTVAL = BUTVAL +1
IF BUTVAL > 6 THEN BUTVAL = 6
IF BUTDN = 1 THEN BUTVAL = BUTVAL -1
IF BUTVAL < 0 THEN BUTVAL = 0
LEDSON: 'SUBROUTINE FOR TURNING ON LEDs
IF BUTVAL > 0 THEN PORTB.0 = 1
IF BUTVAL >= 1 THEN PORTB.1 = 1
IF BUTVAL >= 2 THEN PORTB.2 = 1
IF BUTVAL >= 3 THEN PORTB.3 = 1
IF BUTVAL >= 4 THEN PORTB.4 = 1
IF BUTVAL = 5 THEN PORTB.5 = 1
IF BUTVAL = 0 THEN PORTB = 0
GOTO MAIN
LIST P=16F84 ; list directive to define processor
ERRORLEVEL -302 ; Turn off bank select warnings
include <p16F84.inc> ; processor specific variable definitions
__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC
; Code protect off, watch dog timer off, power up timer enable, crystal oscillator
COUNTER equ 0x20 ; equate your file (variable) names to memory spaces.
; See data sheet for valid locations.
org 0x000 ; Reset vector
goto Start
org 0x004 ; Interrupt vector
nop ; Not using interrupts in this program.
retfie
Start ; Initial startup. See documentation on I/O ports.
bcf STATUS, RP0 ; Ensure Bank 0
clrf PORTA ; clear data latches
clrf PORTB
bsf STATUS, RP0 ; Select Bank 1
movlw 0xFF ; All inputs
movwf TRISA ; set data direction for Port A.
clrf TRISB ; Port B will be all output.
bcf STATUS, RP0 ; Bank 0.
clrf COUNTER ; Make sure counter starts at 0.
Main
btfss PORTA, 0 ; Test the button on Port A. If set (high), skip next instruction.
call ButtonUp ; This is executed only if A0 is low (button pressed).
btfss PORTA, 1
call ButtonDown
goto Main ; Loop back and test again.
ButtonUp
movlw 0x06 ; Set working register to 6, the highest valid value.
xorwf COUNTER, W ; XOR the counter variable with the working register, store result in W.
; If all bits in COUNTER match 6 (00000110), result is zero. STATUS, Z is auto set.
btfsc STATUS, Z ; If the zero bit is clear, then skip the next instruction.
return ; Otherwise, the counter is at 6 and shouldn't be incremented anymore.
incf COUNTER, F ; Increment COUNTER variable by 1, store back into file COUNTER.
bsf STATUS, C ; Turn on the carry bit, since the RLF rotates left through the carry bit.
rlf PORTB, F ; Shift the bits on PortB left once so the LED bar grows.
return
ButtonDown
clrw ; Set working register to 0, the lowest valid value.
xorwf COUNTER, W ; The rest is the same idea as above.
btfsc STATUS, Z
return
rrf PORTB, F ; Shift the bits right so the LED bar shrinks.
bcf STATUS, C ; Clear the carry bit that the rrf just set.
decf COUNTER, F ; Decrement COUNTER by 1, store back into file COUNTER.
return
end ; Let MPLAB know we're done.