![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | LinkBack | Thread Tools | Display Modes |
| | (permalink) |
| hmmm ...i had that same problem when i used the dos version of Mpasm... you are using the windows version ? right | |
| |
| | (permalink) |
| i am using the windows version im affraid
__________________ In the game of life the fact is, everyone loses, but I sure enjoy playing. | |
| |
| | (permalink) |
| did you use notepad to save it to? if not use notepad | |
| |
| | (permalink) |
| yes i used notepad (did i have to save it somewhere other than my desktop???
__________________ In the game of life the fact is, everyone loses, but I sure enjoy playing. | |
| |
| | (permalink) |
| no the desktop is a good place for it.. i dont know what to tell you.. the problem was mpasm could not find the .inc file | |
| |
| | (permalink) |
| i will be back in a couple of hours | |
| |
| | (permalink) |
| it appears that this programme dosnt like being unzipped to a folder on the destop and it dosnt like path names greater than 63 charactors which seems a lot but its not in win2000 server so i put it all in the root of c and it only has one error that is as listed below Code: 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)
__________________ In the game of life the fact is, everyone loses, but I sure enjoy playing. | |
| |
| | (permalink) |
| My first thought is that you were told to, and presumably did?, download MPASM!. MPASM hasn't been available as a seperate download for a LONG! time - the only seperate version on the MicroChip is probably too old to support the 16F628. What you should do, and what I do, is download and install the latest version of MPLAB - this includes the modern version of MPASM. I then just use MPASM and ignore MPLAB :-) As you have already found out, MPASM doesn't like long file names, stick to standard DOS 8.3 ones - you don't need to be in the root directory, but only use short directory names. | |
| |
| | (permalink) |
| as usual your advise was correct (give me an once of what you have ive not been right about anything for 20yrs in fact now that i mention it since the moment i said i do in church lol) thanks Nigel 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???
__________________ In the game of life the fact is, everyone loses, but I sure enjoy playing. | |
| |
| | (permalink) | |
| Quote:
| ||
| |
| | (permalink) |
| ok well ive managed to do it well the biggest part of it and although i would like it to be smaller here it is in assembler which i believe is your forte im going to try to make it smaller Code: 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 im sure there is a simpler way of doing it in assembler but im stupid.[/quote]
__________________ In the game of life the fact is, everyone loses, but I sure enjoy playing. | |
| |
| | (permalink) |
| sorry about Mpasm i didnt know it was an older version | |
| |
| | (permalink) |
| hey no problem i learned that it dosnt like paths longer than 63 charactors how many people know that i wonder lol
__________________ In the game of life the fact is, everyone loses, but I sure enjoy playing. | |
| |
| | (permalink) |
| Ricardoco, if you are still interested try this code. Code: 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
__________________ I like to tell people I have the heart of a young boy. Then I say it\'s in a jar on my desk. - Stephen King | |
| |
| | (permalink) |
| Not to steal anyone's thunder or anything, but here's a quick crash course on starting out an assembly project in MPLAB. I hope you all don't mind the large message. I've also taken the liberty of coding your project. The code is pretty efficient, and is thoroughly commented. Together with the data sheet, I hope it helps your understanding. Download the latest version of MPLab from Microchip's website. http://www.microchip.com Go to Products / Development Tools then Software. Run MPLab. Go to the Project menu, select Project Wizard. Select your device, which would be the 16F84 or 16F84A, depending on which exact one it is. When it asks for the Tool Suite, you might get an error for the MPLIB Librarian module. I got this back when I first installed it last summer. In order to "find" this program, use the same path as the other two files listed, and add the filename that is is looking for. Typically this would be "C:\Program Files\MPLAB IDE\MCHIP_Tools\mplib.exe". Give the project a name, such as Volume Buttons, and of course a directory to store it on the hard drive. On the next screen, don't worry about adding or removing any files to/from the project. Just click next. Then Finish. Go to File / New. It will bring up an Untitled text window. Save this as volume.asm in the project directory you created a few steps ago. In the original project window, labeled Volume Buttons.mcw, right click on Source Files. Click Add. Then select your asm file you just saved. The following picture is how I generally connect switches. This causes them to function as active low. When the button is not pressed, the PIC input pin sees the +5 volts through the resistor. When the button is pressed, the input pin sees 0v ground, as the 5 volts is dropped across the resistor. This makes sure the input pin sees a signal at all times, and is never floating. The capacitor debounces the switch. ![]() Paste all of the following code into your blank volume.asm. I don't have access to my PICs and programmer tonight, so I had to run it in the simulator. Everything seems to work fine in it. Hopefully it will on the real thing too. Code: 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. | |
| |