![]() | ![]() | ![]() |
| |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
| | Tools |
| | #1 |
|
I'm having trouble getting some code going to do what I'd expect it to do. Can I have some pointers? Here's my code: Code: ;********************************************************************************
;Set up the assembler options (Chip type, clock source, other bits and pieces)
LIST p=16F88, r=DEC
#include <P16F88.inc>
__CONFIG _CONFIG1, _INTRC_IO & _MCLR_ON & _WDT_OFF & _LVP_OFF
;********************************************************************************
;********************************************************************************
;Start of the main program
STATUS equ 03h ;this assigns the word STATUS to the value of 03h,
;which is the address of the STATUS register.
TRISB equ 86h ;This assigns the word TRISB to the value of 86h,
;which is the address of the Tri-State register for PortB
PORTB equ 06h ;This assigns the word PORTB to 06h which is the
;address of Port B.
;********************************************************************************
bsf STATUS,5 ; select Bank 1
movlw 00h ; set the W register to 00h which
movwf TRISB ; sets all pins on PortB as outputs
bcf STATUS,5 ; select Bank 0
;Start of the main program
Start movlw b'10' ; put binary value in W register to
movwf PORTB ; set PortB.1 high an PortB.0 low
; movlw b'00' ; put binary value in W register to
; movwf PORTA ; set both PortB pins low again
goto Start ; rinse'n'repeat!
END
I thought this code would set PortB.1 high, but testing with a voltmeter I don't see that happening (it just kind of sits like most of the other PortB pins around 0.05V when the power's on). Everything after "Start of main program," is mine, but the code before that is part of the header I've copied from what GCBASIC compiles to initialize the chip. There's a variety of other stuff I cut that GCBASIC does by default to initialize the chip, too, so maybe there's something I'm missing about that, too? Last edited by Hank Fletcher; 8th June 2008 at 08:31 PM. | |
| |
| | #2 |
|
MPLABs built in simulator should be your first line of troubleshooting. First thing I noticed was you're missing an ORG statement. ORG 0x000 Will tell MPASM where to put the code. Second copy & paste from a compiled language is not a good idea IMO. Your program should redefine definitions like the example you posted. Last edited by blueroomelectronics; 8th June 2008 at 08:35 PM. | |
| |
| | #3 |
|
If you have an ICD or the Simulator you can single step through the program, else the LED turns on & off way to fast to see. Code: LIST p=16F88, r=DEC
#include <P16F88.inc>
__CONFIG _CONFIG1, _INTRC_IO & _MCLR_ON & _WDT_OFF & _LVP_OFF
org 0x000
bsf STATUS,RP0 ; select Bank 1
movlw 0x00 ; set the W register to 00h which
movwf TRISB ; sets all pins on PortB as outputs
bcf STATUS,RP0 ; select Bank 0
;Start of the main program
Start movlw b'00000010' ; put binary value in W register to
movwf PORTB ; set PortB.1 high an PortB.0 low
movlw b'00000000' ; put binary value in W register to
movwf PORTB ; set both PortB pins low again
goto Start ; rinse'n'repeat!
END
| |
| |
| | #4 | |
| Quote:
Code: LIST p=16F88, r=DEC These are unnecessary and redundant: Code: STATUS equ 03h ;this assigns the word STATUS to the value of 03h,
;which is the address of the STATUS register.
TRISB equ 86h ;This assigns the word TRISB to the value of 86h,
;which is the address of the Tri-State register for PortB
PORTB equ 06h ;This assigns the word PORTB to 06h which is the
;address of Port B.
Code: #include <P16F88.inc> Instead of this: Code: bsf STATUS,5 ; select Bank 1 movlw 00h ; set the W register to 00h which movwf TRISB ; sets all pins on PortB as outputs bcf STATUS,5 ; select Bank 0 Code: banksel TRISB ;bank 1 movlw 0x00 movwf TRISB banksel PORTA ;bank 0 You need an org statement before your code starts Code: org 0x00
Start movlw b'00000010' ; put binary value in W register to
movwf PORTB ; set PortB.1 high an PortB.0 low
; movlw 0 ; put binary value in W register to
; movwf PORTA ; set both PortB pins low again
goto Start ; rinse'n'repeat!
__________________ ========================= Futz's Microcontrollers & Robotics ========================= Last edited by futz; 8th June 2008 at 08:47 PM. | ||
| |
| | #5 | |
|
Is this better? It's all me, although I'm trying to adapt the code from a tutorial to use PortA instead of PortB. Code: ORG 0x000
;********************************************************************************
;Start of the main program
STATUS equ 03h ;this assigns the word STATUS to the value of 03h,
;which is the address of the STATUS register.
TRISB equ 86h ;This assigns the word TRISB to the value of 86h,
;which is the address of the Tri-State register for PortB
PORTB equ 06h ;This assigns the word PORTB to 06h which is the
;address of Port B.
;********************************************************************************
bsf STATUS,5 ; select Bank 1
movlw 00h ; set the W register to 00h which
movwf TRISB ; sets all pins on PortB as outputs
bcf STATUS,5 ; select Bank 0
;Start of the main program
Start movlw b'10' ; put binary value in W register to
movwf PORTB ; set PortB.1 high an PortB.0 low
; movlw b'00' ; put binary value in W register to
; movwf PORTA ; set both PortB pins low again
goto Start ; rinse'n'repeat!
END
2) I don't know what you mean by this: Quote:
Thanks. | ||
| |
| | #6 |
|
Whoa! Thanks for the fast response, guys! Just give me a second to read what you've written.
Last edited by Hank Fletcher; 8th June 2008 at 08:41 PM. | |
| |
| | #7 |
|
LOL you'll have to scroll up to see my version of your program Meh here it is againCode: LIST p=16F88, r=DEC
#include <P16F88.inc>
__CONFIG _CONFIG1, _INTRC_IO & _MCLR_ON & _WDT_OFF & _LVP_OFF
org 0x000
bsf STATUS,RP0 ; select Bank 1
movlw 0x00 ; set the W register to 00h which
movwf TRISB ; sets all pins on PortB as outputs
bcf STATUS,RP0 ; select Bank 0
;Start of the main program
Start movlw b'00000010' ; put binary value in W register to
movwf PORTB ; set PortB.1 high an PortB.0 low
movlw b'00000000' ; put binary value in W register to
movwf PORTB ; set both PortB pins low again
goto Start ; rinse'n'repeat!
END
| |
| |
| | #8 |
|
I was wondering about banksel as I was working through the tutorial. Is that from the include file, too? How can I know what protocol to follow in accordance with the other details of the include file, such as simply saying "movwf TRISB." Yeah, I saw your program and I'll give it a try - thanks, Bill! Thanks for breaking it down, too, futz. FYI: I know I'm coding to make the LED blink really fast, but I should still be able to read one or two volts off the pin with a multimeter. That's good enough for me right now - this is all part of me learning to toggle two pins fast enough to get some kind of NTSC signal going with just an internal oscillator. Last edited by Hank Fletcher; 8th June 2008 at 08:52 PM. | |
| |
| | #9 |
| If the pin is toggling at anything faster than once every second or two, forget about getting a reading with a multimeter (unless maybe your meter is real high end). They just don't work fast enough. Set the pin high and leave it high and measure and it will read 5V.
__________________ ========================= Futz's Microcontrollers & Robotics ========================= | |
| |
| | #10 |
|
I tried Bill's correction to my program, but it doesn't seem to do anything. Am I missing something really goofy here, like it terms of saving the .asm and .hex and programming the mcu?
| |
| |
| | #11 | |
| Quote:
Last edited by Hank Fletcher; 8th June 2008 at 09:00 PM. | ||
| |
| | #12 |
|
You need a delay, or a scope. The 16F88 runs way to fast to see it flash. I have a demo program for the 16F88 in the Firefly manual, might be helpful. PS it is RB1 (PIN7) your checking right? And you do have a 0.1uf cap near the power pins plus a 10K to 22K pullup on pin4 (MCLR)... Right... Last edited by blueroomelectronics; 8th June 2008 at 09:06 PM. | |
| |
| | #13 |
| More commonly known as "commented out". Remmed was an old BASIC thing from the BASIC "rem", or remark, command.
__________________ ========================= Futz's Microcontrollers & Robotics ========================= Last edited by futz; 8th June 2008 at 09:04 PM. | |
| |
| | #14 |
|
One more thing, this poster should help. It's helped plenty of folks get their first LED flashing. | |
| |
| | #15 | |
| Quote:
| ||
| |
|
| Tags |
| mplab, problem, programming or compiling |
| Thread Tools | |
| Display Modes | |
| |
Similar | ||||
| Title | Starter | Forum | Replies | Latest |
| Programming C in MPLAB | simrantogether | Micro Controllers | 11 | 11th February 2008 07:40 PM |
| Programming PICC through MPLAB | MatrixPhreak | Micro Controllers | 25 | 9th December 2007 04:56 PM |
| Programming HEX file with MPlab/Inchworm | gregmcc | Micro Controllers | 4 | 27th April 2007 04:20 PM |
| compiling with MPLAB | evandude | Micro Controllers | 4 | 9th April 2005 09:08 AM |
| Compiling 16F628A - problem | kenmac | Micro Controllers | 4 | 23rd September 2004 06:00 AM |