Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Am I doing something wrong?

Status
Not open for further replies.

Bryan76

New Member
I am using the following

pic16f84a:
https://www.electro-tech-online.com/custompdfs/2007/04/35007b.pdf

Programmer (icprog):
(JDM Programmer (Ludipipo))

MPLAB IDE v7.51:
**broken link removed**

This is the tutorial code I am using (that i cant get to work correctly) Tutorial with switch:
**broken link removed**


The programmer gives me no errors and I have followed the instructions on how to set it up, including activating the xp/2000 driver. The hardware is getting the needed voltage and I am having no probs with it. First I create a new project in Mplab. I follow the setup and select the pic16f84a micro. Once done with the project wizard I then click new which gives me a blank window to write the code on. I copy and paste the code from Mikes Cybot tutorial to the window and then save as a xxx.asm file. I then right click on the source file and add the xxx.asm file. Once done I select build all. It says BUILD SUCCEEDED but it gives several warnings(image added). So when its all said and done all that seems to happen is that the LED blinks in intervals of approx 2secs. The switch is supposed to double the time but does nothing. I have about 1 1/2 years exp in building the circuits and about 1 month with micros. So please go easy on me if I am missing something obvious :confused:
 

Attachments

  • image.JPG
    image.JPG
    91.8 KB · Views: 224
Try reading what the error messages say!.

It's also very poor tutorial code, as it doesn't have the required header data at the beginning, and doesn't use the proper MicroChip include file.
 
Nigel Goodwin said:
Try reading what the error messages say!.

It's also very poor tutorial code, as it doesn't have the required header data at the beginning, and doesn't use the proper MicroChip include file.

Come on now. I did read the error message! Its a warning and not an error so I did not know if it would actually cause a problem. "proper MicroChip include file" could you explain? thanks.
 
"Found label after column 1" seems pretty explicit?, but some of them are labels (and SHOULD be in column 1), and some are register names - which if are being identified as labels means they aren't working. Very basically, the assembler assumes labels are in column1 one, and the instructions tabbed to column 2.

MicroChip provide an include file for all their processors, which means you don't have to declare them yourself - and it's really poor practice to do so.

The code on that page also doesn't include the essential settings for the assembler, if you're not setting them yourself elsewhere - that's now going to help, again it's REALLY BAD PRACTICE not to have all that in the file.
 
Nigel Goodwin said:
"Found label after column 1" seems pretty explicit?, but some of them are labels (and SHOULD be in column 1), and some are register names - which if are being identified as labels means they aren't working. Very basically, the assembler assumes labels are in column1 one, and the instructions tabbed to column 2.

MicroChip provide an include file for all their processors, which means you don't have to declare them yourself - and it's really poor practice to do so.

The code on that page also doesn't include the essential settings for the assembler, if you're not setting them yourself elsewhere - that's now going to help, again it's REALLY BAD PRACTICE not to have all that in the file.

I will do some more research on it. Thank you.
 
It's a very poor tutorial, and wrong too. The assembled code is only 18bytes not the 124 suggested at the end of the document. I was too lazy to include the _CONFIG settings (which should be added for proper operation) I've got the end of a Flu and I don't use the 84A and nor should anyone else (it's way old and costs more than the newer and better 16F628A that replaced it a decade ago).

PS pity the poor souls who tried to build the Cybot

**broken link removed**
Hey Nigel, you did the PIC board, what happened to the Cybot?


Code:
;*****Set up the Constants****
    list     p=16F84A
    include <p16F84A.inc>
COUNT1  = 0x08
COUNT2  = 0x09
;****Set up the port**** 
       org       0x000            ; reset vector
       bsf       STATUS,RP0   ;Switch to Bank 1
       movlw   b'00000001'    ;Set the Port A pins
       movwf   TRISA           ;bit 1to output, bit 0 to input.
       bcf       STATUS,RP0   ;Switch back to Bank 0 
       movlw   0x02             ; Set up our w register with 02h 

;****Turn the LED on and off**** 
Start                 
       xorwf    PORTA,1     ; toggle the LED 

;****Check if the switch is closed
       btfsc     PORTA,0         ; test the bit value from PORTA,0 
       call       Delay           ; carry on as normal.
                                ; If is a 1, then add an
                                ; extra delay routine                                                                 
        call    Delay           ; ****Add a delay 

;****Check if the switch is still closed
        btfsc   PORTA,0         ; test the value from PORTA,0
        call    Delay           ;carry on as normal.
                                ;If is a 1, then add an
                                ;extra delay routine 
;****Add another delay**** 
        call       Delay 

;****Now go back to the start of the program
        goto       Start        ;go back to Start and turn LED on again 

;****Here is our Subroutine
Delay
Loop1   decfsz  COUNT1,1        ;This second loop keeps the L
           goto     Loop1           ;turned off long enough for us to
           decfsz  COUNT2,1        ;see it turned off
           goto     Loop1           ;
           return 

           end
 
Last edited:
blueroomelectronics said:
It's a very poor tutorial, and wrong too. The assembled code is only 18bytes not the 124 suggested at the end of the document. I was too lazy to include the _CONFIG settings (which should be added for proper operation) I've got the end of a Flu and I don't use the 84A and nor should anyone else (it's way old and costs more than the newer and better 16F628A that replaced it a decade ago).

PS pity the poor souls who tried to build the Cybot

**broken link removed**
Hey Nigel, you did the PIC board, what happened to the Cybot?


Code:
;*****Set up the Constants****
    list     p=16F84A
    include <p16F84A.inc>
COUNT1  = 0x08
COUNT2  = 0x09
;****Set up the port**** 
       org       0x000            ; reset vector
       bsf       STATUS,RP0   ;Switch to Bank 1
       movlw   b'00000001'    ;Set the Port A pins
       movwf   TRISA           ;bit 1to output, bit 0 to input.
       bcf       STATUS,RP0   ;Switch back to Bank 0 
       movlw   0x02             ; Set up our w register with 02h 

;****Turn the LED on and off**** 
Start                 
       xorwf    PORTA,1     ; toggle the LED 

;****Check if the switch is closed
       btfsc     PORTA,0         ; test the bit value from PORTA,0 
       call       Delay           ; carry on as normal.
                                ; If is a 1, then add an
                                ; extra delay routine                                                                 
        call    Delay           ; ****Add a delay 

;****Check if the switch is still closed
        btfsc   PORTA,0         ; test the value from PORTA,0
        call    Delay           ;carry on as normal.
                                ;If is a 1, then add an
                                ;extra delay routine 
;****Add another delay**** 
        call       Delay 

;****Now go back to the start of the program
        goto       Start        ;go back to Start and turn LED on again 

;****Here is our Subroutine
Delay
Loop1   decfsz  COUNT1,1        ;This second loop keeps the L
           goto     Loop1           ;turned off long enough for us to
           decfsz  COUNT2,1        ;see it turned off
           goto     Loop1           ;
           return 

           end



Awesome help. Thanks for your time. I will get to work on this.
 
:mad: :confused: :mad:

Oh well its still doing the same thing. Blinking in intervals of 3 secs. When I apply a high to RA0 I still get no change in the 3 sec interval. :eek:
Im about to abandon this project :(
 
I just corrected the code to compile, I didn't fix it. There are plenty of good code examples out there. Try Nigels for one.

PS make sure that there is a pullup or pulldown on the switch. Port A has no built in pullup.

Or hook up a SPDT switch, with center pin to A0, one to +5 the other to GND
 
Last edited:
blueroomelectronics said:
I just corrected the code to compile, I didn't fix it. There are plenty of good code examples out there. Try Nigels for one.

PS make sure that there is a pullup or pulldown on the switch. Port A has no built in pullup.

Or hook up a SPDT switch, with center pin to A0, one to +5 the other to GND

Will do. Thanks
 
Have you considered a higher language such as PIC Basic?

A simple flashing LED if a switch is pressed would be as simple as;


Code:
Symbol Switch  = PORTB.0
Symbol LED = PORTB.1

[B]Input[/B] Switch
[B]Low[/B] LED

Main_Loop:

   [B] If[/B] Switch = 1 [B]Then[/B]
       Toggle LED
    [B]Else[/B]
       LED = 0
   [B] EndIf[/B]


    [B]DelaymS[/B] 200
     
    [B]Goto[/B] Main_Loop
 
Last edited:
blueroomelectronics said:
BASIC will hide a fair amount of power from most users.

PIC Basic is anything but 'Power hiding', especially in situations which involve moderate complexity or require significant maintainability. If it’s a structured approach you’re looking for, PIC Basic caters for both ends of the market.

It’s an old fallacy that Assembler offers faster/stable code. How many users do you see programming their PC with assembly? Higher languages offer that modular structured approach that allows your complexity too build on the external circuit rather than Bit Crunching your way through algorithms in assembly.

Keep in mind there are many development suits out there too choose from, each with different strengths, and some that are complete junk.

blueroomelectronics said:
And it's generally not free or very crippled.

For the learner, almost every compiler offers a more than generous 'Lite' version. At the end of the day, you get what you pay for.

  • **broken link removed** offers 50 Lines of PIC Basic code & a limited range of PICs (but includes the 16F628A and 16F877) with the Lite Version
  • mikroBasic offers 2000 Lines of Compiled Code, no RAM/PIC limitations.

  • [*]Swordfish
    is simply the most advanced and structured approach available to PIC programming at an affordable price. It only caters for 18F PIC micro's. Limited to 200 bytes of RAM (variables), no PIC/Program length restrictions

By all means, a basic understanding of assembly would be a great back bone to your future development with PIC's, but I wouldn't get too rapped up in it.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top