Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

16F627 with PICBASIC Pro, flash an led 292 times per second

Status
Not open for further replies.

eric0524

Newbie level 2
Joined
Apr 13, 2010
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Florida
Activity points
1,294
I am new at this so please be patient. I am tring to write some code that flashes an led 292 times per second for 30 minutes. Every time I try I get differnt results with a new power supply. It's suppose to run 30 minutes at 292hz then pause 20 minutes (the 20 minute pause is the only thing I have right). Can anyone help with my spagetti code (that I inherited)? I am using a 16F627 with PICBASIC Pro. The only ocillator I have is the onboard one in the 16F627.


Code:
DEFINE OSC 4

Out VAR Portb.7
Green VAR Portb.2
Yellow VAR Portb.0
Out2 VAR portb.5
 
EE VAR Word
FF VAR Word
X VAR Word
CMCON = 7
 
FF = 1
EE = 1
High Green
Low Yellow
' Run out at 292hz for 30 minutes.........not happening always
FOR FF = 1 TO 5267
    FOR EE = 1 TO 100
        High Out
        High Out2
        PAUSEUS 2102
        Low Out
        Low Out2
        PAUSEUS 1400
    NEXT EE
NEXT FF
'Put every thing off and change the status LED to Yellow
Low Out
Low out2
Low Green
High Yellow
' Pause for 20 minutes before doing it again.
X = 1
For X = 1 to 20
    Pause 60000
Next X
 

Re: Pic 16F627 Freq Problem

Well basic is not my thing so I'm not sure how this works.

I cant see where you set the tristate registers to define the ports as inputs or outputs?

Also, at the end of the program, shouldn't you have a 'GOTO Start' and a 'Start:' label at the beginning of the program it should loop back to?

At the moment, your program ends, the micro will reset, and you will start at the 'CMCON = 7' instruction.
After reset, all the ports will default to inputs.
 

Re: Pic 16F627 Freq Problem

It actually just has the same for next on the FF loop then sets everything to low and then an END statement. Sorry, I didn't get the whole paste in there.

Code:
DEFINE OSC 4
'DEFINE OSCCAL_1K 1                
CMCON = 7

Green VAR Portb.2
Yellow VAR Portb.0
Out VAR Portb.7
Out2 VAR portb.5
 
EE VAR Word
FF VAR Word
X VAR Word
 
FF = 1
EE = 1
High Green
Low Yellow
' Run out at 292hz for 30 minutes.........not happening always
FOR FF = 1 TO 5267
    FOR EE = 1 TO 100
        High Out
        High Out2
        PAUSEUS 2102
        Low Out
        Low Out2
        PAUSEUS 1400
    NEXT EE
NEXT FF
'Put every thing off and change the status LED to Yellow

Low Out
Low out2
Low Green
High Yellow
' Pause for 20 minutes before doing it again.
X = 1
For X = 1 to 20
    High Yellow
    Pause 59900
    low yellow
    pause 100
Next X

FF = 1
EE = 1
High Green
Low Yellow

FOR FF = 1 TO 5267
    FOR EE = 1 TO 100
        High Out
        High Out2
        PAUSEUS 2102
        Low Out
        Low Out2
        PAUSEUS 1400
    NEXT EE
NEXT FF

Low Green
Low Yellow
Low Out
Low Out2

END
 

Re: Pic 16F627 Freq Problem

I still cant see were you set the ports to outputs?
At reset, by default, all ports are set as inputs.

You normally write to the TRIS register a '0' to set a port as output or a '1' to set the port as input.

You would also normally have a label at the start of the program, such as
START:

and at the end of the program you would have a jump such as
GOTO START.

This would make the program loop and keep repeating.

Your program runs through to the end and then, well, ends?

This would cause the micro to reset and start at the beginning again.
After reset, the ports, by default are inputs.

But as I said, I'm not to familiar with the basic compiler you are using.
Maybe it sets the I/O in a mysterious way???
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top