Hello.
As I have gotten the LED blinking code to work (following a tutorial of course) I have decided I want to continue in this field. I am very much interested in learning to be able to program, and the GCBASIC is just so easy to grasp.
Now, I have written a code for a POV toy, you know you wave some LEDs in the air and they spell out words. This is the code so far, but it seems it might not (and does not) work. If someone can help me fix it, it would be so much appreciated. By the way, it is for the 16F628A chip.
------------------
#chip 16F628A, 4
DIM A(4)
DIM A(1) AS BYTE
DIM A(2) AS BYTE
DIM A(3) AS BYTE
DIM A(4) AS BYTE
A(1) = 252
A(2) = 51
A(3) = 51
A(4) = 252
Start:
For var = 1 TO 4
Portb = A(var)
wait 8 ms
Next
goto Start
---------------------
Thanks a lot,
-Omar
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
There are a couple of things in your program that need to be altered to make it 100% correct.
Only the first DIM command is needed - there is no need to set up the individual elements in an array. I'll alter GCBASIC so that it can give an error message about that.
The other thing is that a #config line might be needed. If you are using a crystal and have a pull up resistor on MCLR then the program will be fine as is. Otherwise, adding this line will help:
#config MCLRE_OFF, INTOSC_OSC_NOCLKOUT
This will set the configuration of the PIC chip correctly so that it will work without a pull up resistor or crystal.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you very much sir.
I am using a ceramic resonator, so I should turn it off indeed.
One more thing, do I need to define my PORTB as an output such as:
dir PORTB.0 OUT
dir PORTB.1 OUT
dir PORTB.2 OUT
dir PORTB.3 OUT
dir PORTB.4 OUT
dir PORTB.5 OUT
dir PORTB.6 OUT
dir PORTB.7 OUT
One more question, am I allowed to use binary for the values, instead of converting them into decimal?
For example, can I set
A(2) = 00110011
or must I do
A(2) = 51
Thank you very much,
-Omar
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yes, you do need to set PORTB as an output. The code you posted will work perfectly, but a simpler way is to set the direction of the whole port at once like this:
dir PORTB out
It is possible to use binary numbers in GCBASIC, as long as you use "b'" to mark the numbers as binary. For example, this will work:
A(2) = b'00110011'
Incidentally, hexadecimal can also be used - add 0x to the start of a number to mark it as hex.
The #config line I posted earlier tells the 16F628A to use its built in oscillator. If you would prefer to use a ceramic oscillator, please use this line instead:
#config XT_OSC, MCLRE_OFF
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Sorry to bother yet again, but as you know I am making a little LED toy with this code.
Would you be able to tell me which pins need to have LEDs on them (preferably in what order on my breadboard) so I can see this in action properly.
At first I thought of just sticking LEDs on the PortB pins, but I am not sure if this will correctly display the patterns.
Thank you very much,
Omar
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
How many LEDs are there? I'm assuming that you have 8, which are all connected to PORTB?
If so, then
LED 1 connects to PORTB.0, which is pin 6 on the 628A
LED 2 connects to PORTB.1, which is pin 7 on the 628A
LED 3 connects to PORTB.2, which is pin 8 on the 628A
...
LED 8 connects to PORTB.7, which is pin 13 on the 628A
All of the LEDs will need to line up in order on the breadboard, with LED 1 at one end and LED 8 at the other.
Do you have the datasheet for the PIC handy? If not, the datasheet for the 16F628A and similar chips is on the Microchip website at http://ww1.microchip.com/downloads/en/DeviceDoc/40044E.pdf . The pin diagrams in it may be of assistance.
I hope that I have answered your question without simplifying the answer too much - if not, please ask again!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you so much, sir!
That helped very much-- things are working dandy!
If you don't mind me asking an off-topic question:
I kind of fried the chips I had received as samples. Now I have no chips and I really want to do some tinkering over the holidays-- do you know any small sites where I can buy these PIC chips from? I only have Paypal, though.
I was interested in glitchbuster.com (http://www.glitchbuster.com/) but I have not recieved a reply for 2 weeks...
Thank you so much,
Omar
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello.
As I have gotten the LED blinking code to work (following a tutorial of course) I have decided I want to continue in this field. I am very much interested in learning to be able to program, and the GCBASIC is just so easy to grasp.
Now, I have written a code for a POV toy, you know you wave some LEDs in the air and they spell out words. This is the code so far, but it seems it might not (and does not) work. If someone can help me fix it, it would be so much appreciated. By the way, it is for the 16F628A chip.
------------------
#chip 16F628A, 4
DIM A(4)
DIM A(1) AS BYTE
DIM A(2) AS BYTE
DIM A(3) AS BYTE
DIM A(4) AS BYTE
A(1) = 252
A(2) = 51
A(3) = 51
A(4) = 252
Start:
For var = 1 TO 4
Portb = A(var)
wait 8 ms
Next
goto Start
---------------------
Thanks a lot,
-Omar
There are a couple of things in your program that need to be altered to make it 100% correct.
Only the first DIM command is needed - there is no need to set up the individual elements in an array. I'll alter GCBASIC so that it can give an error message about that.
The other thing is that a #config line might be needed. If you are using a crystal and have a pull up resistor on MCLR then the program will be fine as is. Otherwise, adding this line will help:
#config MCLRE_OFF, INTOSC_OSC_NOCLKOUT
This will set the configuration of the PIC chip correctly so that it will work without a pull up resistor or crystal.
Thank you very much sir.
I am using a ceramic resonator, so I should turn it off indeed.
One more thing, do I need to define my PORTB as an output such as:
dir PORTB.0 OUT
dir PORTB.1 OUT
dir PORTB.2 OUT
dir PORTB.3 OUT
dir PORTB.4 OUT
dir PORTB.5 OUT
dir PORTB.6 OUT
dir PORTB.7 OUT
One more question, am I allowed to use binary for the values, instead of converting them into decimal?
For example, can I set
A(2) = 00110011
or must I do
A(2) = 51
Thank you very much,
-Omar
Yes, you do need to set PORTB as an output. The code you posted will work perfectly, but a simpler way is to set the direction of the whole port at once like this:
dir PORTB out
It is possible to use binary numbers in GCBASIC, as long as you use "b'" to mark the numbers as binary. For example, this will work:
A(2) = b'00110011'
Incidentally, hexadecimal can also be used - add 0x to the start of a number to mark it as hex.
The #config line I posted earlier tells the 16F628A to use its built in oscillator. If you would prefer to use a ceramic oscillator, please use this line instead:
#config XT_OSC, MCLRE_OFF
Sorry to bother yet again, but as you know I am making a little LED toy with this code.
Would you be able to tell me which pins need to have LEDs on them (preferably in what order on my breadboard) so I can see this in action properly.
At first I thought of just sticking LEDs on the PortB pins, but I am not sure if this will correctly display the patterns.
Thank you very much,
Omar
How many LEDs are there? I'm assuming that you have 8, which are all connected to PORTB?
If so, then
LED 1 connects to PORTB.0, which is pin 6 on the 628A
LED 2 connects to PORTB.1, which is pin 7 on the 628A
LED 3 connects to PORTB.2, which is pin 8 on the 628A
...
LED 8 connects to PORTB.7, which is pin 13 on the 628A
All of the LEDs will need to line up in order on the breadboard, with LED 1 at one end and LED 8 at the other.
Do you have the datasheet for the PIC handy? If not, the datasheet for the 16F628A and similar chips is on the Microchip website at http://ww1.microchip.com/downloads/en/DeviceDoc/40044E.pdf . The pin diagrams in it may be of assistance.
I hope that I have answered your question without simplifying the answer too much - if not, please ask again!
Thank you so much, sir!
That helped very much-- things are working dandy!
If you don't mind me asking an off-topic question:
I kind of fried the chips I had received as samples. Now I have no chips and I really want to do some tinkering over the holidays-- do you know any small sites where I can buy these PIC chips from? I only have Paypal, though.
I was interested in glitchbuster.com (http://www.glitchbuster.com/) but I have not recieved a reply for 2 weeks...
Thank you so much,
Omar
I have bought a lot of stuff at this site and like it pretty well:
http://www.futurlec.com/
Lots of pic and related stuff
Russ