PDA

View Full Version : Newb Question...



Perrin`
- 2nd January 2009, 19:43
For starters: MPLab 8.10, ICD2, PIC12F629, PBP 2.50a
Initializations

Include "modedefs.bas"

trisio =%110000

red var gpio.0 'red
blue var gpio.1 'blue
buzzer var gpio.2 'buzzer
Contact var gpio.4 'Input1
Contact1 var gpio.5 'Input2
i var byte 'general counter
k var byte 'general counter


My initializations stay the same for all below.



main:
red=0
blue=1
pause 500

blue=0
red=1
pause 500

goto main


This code alternates a red and blue LED as expected. Good.







main:
red=0
blue=1
pause 500

red=1
blue=0
pause 500

goto main

This code... blue light comes on... blue light goes off(red doesnt come on). Not good. Shouldnt they alternate???



main:
blue=1
red=0
pause 500

red=1
blue=0
pause 500

goto main

This code... nothing happens. ??? Shouldnt they alternate


main:
blue=1
red=1
pause 500

goto main

This program results in only red. I think it should result in both?





The above programs and results were done in my 12f629. This is my first time with such a weak PIC, but its job is super simple and its the cheapest and smallest PIC we stock here. I put the same code into my 18F2520 and 4520s and they act as I would expect they act. Could someone explain to me why it appears to be only taking the last variable I use, be it red or blue and using that one. Am I expecting something wrong? If so why are my expectations correct for the 2520 series?






So I've been programming with PBP for quite a while now, about 6 months. I think i've done some pretty complex and advanced programs in PBP and now I feel kind of bad with this ultra-noob question.

PBP was my first experience with MCUs(I had programmed my fair share of things, but all in C, or basic on a PC), consequently I was not... enamoured so to speak with PBP. This semester I took a class on MCU's and programmed the entire class in assembly, and did my class final project in C.(We used freescale... eww.) Consequently... I'm back to PBP and PICs and I have a much higher impression of how truly useful and easy it is but this just baffles me. Its so simple... am I missing something obvious?

Melanie
- 2nd January 2009, 19:51
What happens if you were to put a Pause 1 between the Red and Blue?

main:
red=0
pause 1
blue=1
pause 500

red=1
pause 1
blue=0
pause 500

goto main

Perrin`
- 2nd January 2009, 20:06
I copy and pasted your suggestion and it flashed Blue On, Blue off(red off), Blue On, Blue Off(red off)... and so forth.

Melanie
- 2nd January 2009, 20:22
OK Melanie... always look at the Datasheet... turn the Comparator OFF... Put this in before your loop...

CMCON=7

Perrin`
- 2nd January 2009, 20:49
Well that was it... Now I'm off to find where I missed it in the datasheet... RTFM failure.:mad:

Ninja:

Unprecedented failure... the giant gray box that says NOTE:

Sometimes I feel like a numbnuts.

Thanks Melanie!