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.
USB is probably a lot of overkill for this application, perhaps the USART would be suffice?

I should have though before I typed earlier, Use Swordfish if your heading down the 18F road, it too has USB support. Many people rate it as the best 18F compiler available considering its time on the market.

USART is serial transfer over a single wire, and communicating with your PC is quite simple via a COM Port. There are many alternatives out there, I use the DS275 and MAX232.

The DS275 is a single chip solution, but costs more, **broken link removed**
The MAX232 requires 4 external capacitors, but is less than half the cost of the DS275, **broken link removed** (still being designed - but the jist of it is there)

The reason why you need another device to buffer between the PIC and the PC is because of the large voltages that the RS232 signals from the PC have. The 'interface' device acts like a buffer, and reduces the signals to 0 to 5V.

A simple, crude series resistor would limit the current, but is not really recommended...

Now you can bypass the USB learning curve and settle for something a little simpler.
 
gramo said:
USB is probably a lot of overkill for this application, perhaps the USART would be suffice?

I should have though before I typed earlier, Use Swordfish if your heading down the 18F road, it too has USB support. Many people rate it as the best 18F compiler available considering its time on the market.

USART is serial transfer over a single wire, and communicating with your PC is quite simple via a COM Port. There are many alternatives out there, I use the DS275 and MAX232.

The DS275 is a single chip solution, but costs more, **broken link removed**
The MAX232 requires 4 external capacitors, but is less than half the cost of the DS275, **broken link removed** (still being designed - but the jist of it is there)

The reason why you need another device to buffer between the PIC and the PC is because of the large voltages that the RS232 signals from the PC have. The 'interface' device acts like a buffer, and reduces the signals to 0 to 5V.

A simple, crude series resistor would limit the current, but is not really recommended...

Now you can bypass the USB learning curve and settle for something a little simpler.

Sounds good. Man I am having information overload! This is all good info, I really appreciate it!!! I will look at all the info and links you two have posted and will get to work. If you have anymore ideas or tips please post them on this thread. Thanks a million. :D :D
 
I love the comment in that tutorial.
Code:
                         goto                   Loop1              ;
return 

;****End of the program**** 

end                               ;Needed by some compilers, [COLOR="Red"]and also[/COLOR]
                                  ;[COLOR="red"]just in case we miss the goto instruction.[/COLOR]
LOL

Mike.
 
Moved the switch & LED to PORTB, (we get pullups on PORTB) Try this and possibly the watchdog timer was resetting your code, I've added the config lines to turn it off.
Code:
COUNT1  = 0x08
COUNT2  = 0x09
;****Set up the port**** 
        org     0x000           ; reset vector
    bsf    STATUS,RP0    ; switch to Bank 1
        bsf     OPTION_REG,NOT_RBPU     ;B1 enable weak pullup on PORTB 
        movlw   b'11111101'     ;B1 PORTB I/O direction pins
        movwf   TRISB           ;B1 bit 1to output, bit 0 to input.
        bcf     STATUS,RP0      ; switch back to Bank 0 
    movlw   0x02            ;B0 Set up our w register with 02h 

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

;****Check if the switch is closed
        call    Delay           ; Initial delay         
        btfss   PORTB,0         ;B0 test value from PORTB,0 
    call    Delay           ; switch closed (0) then delay                                                                


;****Check if the switch is still closed
        btfss   PORTB,0         ;B0 test value from PORTB,0
        call    Delay           ; switch closed (0) then delay

;****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
 
Just to make sure your switch works try this simple program.
Code:
;GND to LED with 330ohm resistor to RB1 (pin7)
;Switch to RB0 (pin6) and GND
;*****Set up the Constants****
    list     p=16F84A
    include <p16F84A.inc>
        __CONFIG _XT_OSC & _WDT_OFF ; WDT off, XT OSC
COUNT1  = 0x08
COUNT2  = 0x09
;****Set up the port**** 
        org     0x000           ; reset vector
        bsf    STATUS,RP0    ; switch to Bank 1
        bsf     OPTION_REG,NOT_RBPU     ;B1 enable weak pullup on PORTB 
        movlw   b'11111101'     ;B1 PORTB I/O direction pins
        movwf   TRISB           ;B1 bit 1to output, bit 0 to input.
        bcf     STATUS,RP0      ; switch back to Bank 0 

;****Turn the LED on and off**** 
Start   btfss   PORTB,0         ;B0 switch open? 
        bcf     PORTB,1         ;B0 yes turn off LED                                                                
        btfsc   PORTB,0         ;B0 switch closed? 
        bsf     PORTB,1         ;B0 yes turn on LED
        goto    Start
        end
 
Last edited:
blueroomelectronics said:
Just to make sure you switch works try this simple program.
Code:
;GND to LED with 330ohm resistor to RB1 (pin7)
;Switch to RB0 (pin6) and GND
;*****Set up the Constants****
    list     p=16F84A
    include <p16F84A.inc>
        __CONFIG _XT_OSC & _WDT_OFF ; WDT off, XT OSC
COUNT1  = 0x08
COUNT2  = 0x09
;****Set up the port**** 
        org     0x000           ; reset vector
        bsf    STATUS,RP0    ; switch to Bank 1
        bsf     OPTION_REG,NOT_RBPU     ;B1 enable weak pullup on PORTB 
        movlw   b'11111101'     ;B1 PORTB I/O direction pins
        movwf   TRISB           ;B1 bit 1to output, bit 0 to input.
        bcf     STATUS,RP0      ; switch back to Bank 0 

;****Turn the LED on and off**** 
Start   btfss   PORTB,0         ;B0 switch open? 
        bcf     PORTB,1         ;B0 yes turn off LED                                                                
        btfsc   PORTB,0         ;B0 switch closed? 
        bsf     PORTB,1         ;B0 yes turn on LED
        goto    Start
        end

I will get to work on it. Hey I got another question. Where is the best place in your opinion(or anyone else who reads this thread)to get pic's from?
 
Bryan76 said:
I will get to work on it. Hey I got another question. Where is the best place in your opinion(or anyone else who reads this thread)to get pic's from?

Well in a thread earlier in the week, someone enlightened me to a cheaper distributor compared to who I was going through before;

www.newark.com


They are really good for IC prices
 
Why always Basic is suggested?

Hola Gramo,

Why so often you suggest to use Basic, when the question doesn't even give way for that?

Is the same that for every question about Basic, another Gramo whould insist in suggesting the use of Assembly.

Simply, you are not answering his question which is what he is looking for.
 
As we talked about it mid way through, the topic went a little left wing...

atferrari said:
Hola Gramo,

Why so often you suggest to use Basic, when the question doesn't even give way for that?

Is the same that for every question about Basic, another Gramo whould insist in suggesting the use of Assembly.

Simply, you are not answering his question which is what he is looking for.

Using higher language programming tools allows for a modular, structured approach to programming, and it just so happens that the BASIC language (called basic because of its mnemonic nature - eg the commands actually do what the say they do, like "PrintAt", "USART.Write" etc), is probably the most popular language on the market for beginner to intermediate programmers.

For beginners, a basic understanding of assembler is great, but don't get wrapped up in it, higher program languages allows you to build your circuits complexity on the outside, not bit crunch away with 32-bit math operations etc in assembly

Download a compiler (like Swordfish/Proton) and have a look through the sample projects. Look at the way these programs are structured, and you'll see the similarities to actual everyday computer programming, and the power that higher program languages hold
 
add my 2cents moved over to pic18's and pic24's too soon,Try coding them in asembler, I just bought into Proton Dev. Suite, I wish I could include Protel in that too . but need to eat and pay the rent. I went with basic and the demo program worked as a test bed for me. as I had a terible time with C.

It works a dream, only problem I have is trying to join **broken link removed** I signed up got my pass word but can't post in forum, yet some one can post a want add for a proton car part.... I have e-mailed crownhill but with the weekend here, I found I needed Google to find some answers for me.

Thanks Gramo , frustrating part is on picbasic forum someone had done part of the code I need :(

regards Art
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top