are you sure its not supposed to be PORTB.1 instead of TRISB? TRIS is used in assembly to set the port directions I believe... but GCBASIC doesnt use that, instead it uses the port name.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
TRISB.1 = 0 is correct. When gcbasic encounters a line of code it does not understand it passes it on to the assembler. Compile the code with trisb.1=0 then look at the assembler listing, compiled.lst, that you will find in the gcbasic folder in the program files folder.
If you are trying to learn PIC programming, let me suggest you go to, www.oshonsoft.com,and download Pic_Sim_Ide. You can use it for small programs without purchase, but for large programs it can be purchase for 29 euro. This software includes a Basic compiler and a simulator. You can write your code and test it right away. The Basic generates an assembly listing which it then assembles. When you know it is working, use your programmer. If it then doesn't work you have a programmer problem.
If you really want to get into PIC programming, then use the 16F877A with a bootloader which you will find on www.oshonsoft.com and then you can skip the programmer.
Richard
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I say it's the #config OSC = INT because another person had a similar problem with a 12f683 and fixed it by adding that line (otherwise it doesn't know if it's getting an external clock or if its gonna run off it's own)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You can also use "set trisb.1 off". The code is then
#Chip 16f628a, 4
set trisb.1 off
LED:
Set PortB.1 on
Wait 1000 ms
Set PortB.1 off
Wait 1000 ms
Goto LED
This compiles and the assembly code looks correct. I recompilied it for a 16F887A and downloaded it with a bootloader and it runs. If that is the case the problem appears to be with your programmer. Are you using compiled.hex? Does the code verify?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
LED:
Set PortB.1 on
Wait 1000 ms
Set PortB.1 off
Wait 1000 ms
Goto LED
The assembly listing for this program shows "_CONFIG _XT_OSC" which means that the chip must have an external resonator or crystal. If you are using the internal osc, you must use "#config osc int".
#Chip 16f628a, 4
#config osc int
set trisb.1 off
LED:
Set PortB.1 on
Wait 1000 ms
Set PortB.1 off
Wait 1000 ms
Goto LED
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
LED:
Set PortB.1 on
Wait 1000 ms
Set PortB.1 off
Wait 1000 ms
Goto LED
The #config osc = int line is needed to tell GCBASIC to make the chip use its internal oscillator. By default, GCBASIC assumes that you're using a crystal unless the chip can't support one.
Regarding setting the pin direction, altering the TRIS register will work but you shouldn't really do it:
- If you switch to a chip that doesn't have TRIS registers, you'll need to change your code
- If you decide to use constants to store the name of the pin, you'll need a constant to store the name of the pin and one to store the name of the TRIS bit.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The wait timeout keeps the chip on it's toes. We don't want it getting complacent on the job do we?
seriously though, it keeps the chip constantly polling PortB.4 to see if it's on, then it keeps polling it to see when it turns off.
at least, thats the general idea of it, i got the idea from the level crossing example in GCbasic
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Could someone tell me why this code doesn't work?
'Hardware
#Chip 16f628a, 4
'Code
LED:
Set PortB.1 on
Wait 1000 ms
Set PortB.1 off
Wait 1000 ms
If 1=1 then
Goto LED
End if
Well, it seems as if the IF statement is whats messing up your program, try
'Hardware
#Chip 16f628a, 4
'Code
LED:
Set PortB.1 on
Wait 1000 ms
Set PortB.1 off
Wait 1000 ms
Goto LED
It still doesn't work, could it have something to do with my programmer?
You need to set port B to outout mode. TRISB.1=0
'Hardware
#Chip 16f628a, 4
'Code
TRISB.1=0
LED:
Set PortB.1 on
Wait 1000 ms
Set PortB.1 off
Wait 1000 ms
Goto LED
It still doesn't work, am I doing something wrong?
dir TRISB.1 out
dir TRISB.1 makes a compiling error.
are you sure its not supposed to be PORTB.1 instead of TRISB? TRIS is used in assembly to set the port directions I believe... but GCBASIC doesnt use that, instead it uses the port name.
'Hardware
#Chip 16f628a, 4
'Code
dir PortB.1 out
LED:
Set PortB.1 on
Wait 1000 ms
Set PortB.1 off
Wait 1000 ms
Goto LED
That doesn't work either... I'm starting to feel really really stupid.
#config OSC = INT
TRISB.1 = 0 is correct. When gcbasic encounters a line of code it does not understand it passes it on to the assembler. Compile the code with trisb.1=0 then look at the assembler listing, compiled.lst, that you will find in the gcbasic folder in the program files folder.
If you are trying to learn PIC programming, let me suggest you go to, www.oshonsoft.com,and download Pic_Sim_Ide. You can use it for small programs without purchase, but for large programs it can be purchase for 29 euro. This software includes a Basic compiler and a simulator. You can write your code and test it right away. The Basic generates an assembly listing which it then assembles. When you know it is working, use your programmer. If it then doesn't work you have a programmer problem.
If you really want to get into PIC programming, then use the 16F877A with a bootloader which you will find on www.oshonsoft.com and then you can skip the programmer.
Richard
I say it's the #config OSC = INT because another person had a similar problem with a 12f683 and fixed it by adding that line (otherwise it doesn't know if it's getting an external clock or if its gonna run off it's own)
You can also use "set trisb.1 off". The code is then
#Chip 16f628a, 4
set trisb.1 off
LED:
Set PortB.1 on
Wait 1000 ms
Set PortB.1 off
Wait 1000 ms
Goto LED
This compiles and the assembly code looks correct. I recompilied it for a 16F887A and downloaded it with a bootloader and it runs. If that is the case the problem appears to be with your programmer. Are you using compiled.hex? Does the code verify?
#Chip 16f628a, 4
set trisb.1 off
LED:
Set PortB.1 on
Wait 1000 ms
Set PortB.1 off
Wait 1000 ms
Goto LED
The assembly listing for this program shows "_CONFIG _XT_OSC" which means that the chip must have an external resonator or crystal. If you are using the internal osc, you must use "#config osc int".
#Chip 16f628a, 4
#config osc int
set trisb.1 off
LED:
Set PortB.1 on
Wait 1000 ms
Set PortB.1 off
Wait 1000 ms
Goto LED
You're getting there! Try this:
#Chip 16f628a, 4
#config osc = int
Dir PORTB.1 Out
LED:
Set PortB.1 on
Wait 1000 ms
Set PortB.1 off
Wait 1000 ms
Goto LED
The #config osc = int line is needed to tell GCBASIC to make the chip use its internal oscillator. By default, GCBASIC assumes that you're using a crystal unless the chip can't support one.
Regarding setting the pin direction, altering the TRIS register will work but you shouldn't really do it:
- If you switch to a chip that doesn't have TRIS registers, you'll need to change your code
- If you decide to use constants to store the name of the pin, you'll need a constant to store the name of the pin and one to store the name of the TRIS bit.
This will also work and there will be no clk output so the RA6 pin can be used for I/O.
#Chip 16f628a, 4
#config intrc_osc_noclkout
set trisb.1 off
LED:
Set PortB.1 on
Wait 1000 ms
Set PortB.1 off
Wait 1000 ms
Goto LED
Richard
Thanks for your help everyone, I finally got it to work and I feel much less stupid now.
Oh, one more question. Why doesn't this work?
#Chip 16f628a, 4
#config osc = int
Dir PortB.4 IN
Dir PORTB.1 Out
'Code
LED:
If PortB.4 = On Then
Set PortB.1 On
Goto LED
End If
Goto LED
I'm trying to make the LED turn on when a switch is closed.
#Chip 16f628a, 4
#config osc = int
#define timeout 10 ms
dir PortB.4 in
dir PortB.1 out
'code
Main:
wait until PortB.4 = true
wait timeout
if not PortB.4 = true then goto main
goto LED
LED:
Set PortB.1 On
wait until PortB.4 = false
wait timeout
if not PortB.4 = false then goto LED
goto Main
May not be the prettiest code, or even optimized, but it "should" work
What does the "wait timeout" do?
The wait timeout keeps the chip on it's toes. We don't want it getting complacent on the job do we?
seriously though, it keeps the chip constantly polling PortB.4 to see if it's on, then it keeps polling it to see when it turns off.
at least, thats the general idea of it, i got the idea from the level crossing example in GCbasic