First of all I would like to compliment the team responsible for this program, GCBASIC is Fantastic!
I DL`d it last night, opened it this morning and wrote a program (that works) before I`d finished my 1`st cup of coffee! :)
Most of it is quite intuitive, and I`m all for keeping stuff simple.
I do have a small problem though, and I`m not entirely sure what`s causing it though?
I`v knocked up a quick prog to turn 4 bit binary into 7 segment HEX display.
and although it works, for some reason the display seems to blink once every 3-4 seconds for no reason I can see?
the display will update to the new binary number faster than this blink rate, so I don`t think it`s a slow prog loop.
I`v altered the uC speed from 1MHz to 4MHz (no change) WDT On and Off (no change) i`m using RC for the clock.
so I`m totally at a loss here?
the code`s using GOTO loops that have every possibility covered (there`s only 16 of them anyway), so I don`t think it`s escaping the LOOP.
my code is as follows:
;Chip Settings
#chip 16C54,1
#config WDT=ON, OSC=RC
Dir a In
Dir b Out
start:
If porta=0x0 then
goto zero
end if
if porta=0x1 then
goto one
end if
if porta=0x2 then
goto two
end if
if porta=0x3 then
goto three
end if
if porta=0x4 then
goto four
end if
if porta=0x5 then
goto five
end if
if porta=0x6 then
goto six
end if
if porta=0x7 then
goto seven
end if
if porta=0x8 then
goto eight
end if
if porta=0x9 then
goto nine
end if
if porta=0xa then
goto ten
end if
if porta=0xb then
goto eleven
end if
if porta=0xc then
goto twelve
end if
if porta=0xd then
goto thirteen
end if
if porta=0xe then
goto fourteen
end if
if porta=0xf then
goto fifteen
end if
zero:
portb= b'01111110'
goto start:
one:
portb= b'00110000'
goto start:
two:
portb= b'01101101'
goto start:
three:
portb= b'01111001'
goto start:
four:
portb= b'00110011'
goto start:
five:
portb= b'01011011'
goto start:
six:
portb= b'01011111'
goto start:
seven:
portb= b'01110000'
goto start:
eight:
portb= b'01111111'
goto start:
nine:
portb= b'01110011'
goto start:
ten:
portb= b'01110111'
goto start:
eleven:
portb= b'00011111'
goto start:
twelve:
portb= b'01001110'
goto start:
thirteen:
portb= b'00111101'
goto start:
fourteen:
portb= b'01001111'
goto start:
fifteen:
portb= b'01000111'
goto start:
a Very simple State Machine in procedure, and yet I cannot see what I have done wrong to make it blink at a 3 to 4 Hz rate?
Anyone?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
select case porta
case 0
zero
case 1
one
case 2
three
.
.
.
case 15
fifteen
end select
wait 30ms 'It's not necessary but you can enter another delay in order to obtain the max of your display
loop
sub zero
portb= b'01111110'
end sub
sub one
portb= b'00110000'
end sub
sub two
portb= b'01101101'
end sub
.
.
.
sub fifteen
portb= b'01000111'
end sub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks, I`v refined the code a little bit more since, and may use the CASE or lookup tables latter, but I still have the same problem with This code too:
start:
if porta=0x0 then
portb= b'01111110'
end if
if porta=0x1 then
portb= b'00110000'
end if
if porta=0x2 then
portb= b'01101101'
end if
if porta=0x3 then
portb= b'01111001'
end if
if porta=0x4 then
portb= b'00110011'
end if
if porta=0x5 then
portb= b'01011011'
end if
if porta=0x6 then
portb= b'01011111'
end if
if porta=0x7 then
portb= b'01110000'
end if
if porta=0x8 then
portb= b'01111111'
end if
if porta=0x9 then
portb= b'01110011'
end if
if porta=0xa then
portb= b'01110111'
end if
if porta=0xb then
portb= b'00011111'
end if
if porta=0xc then
portb= b'01001110'
end if
if porta=0xd then
portb= b'00111101'
end if
if porta=0xe then
portb= b'01001111'
end if
if porta=0xf then
portb= b'01000111'
end if
goto start:
it all works perfectly apart from the display blinking off every 3-4 seconds for about 250mS, but during this time, I can change numbers quite easily, so it`s not the program loop.
there has to be something else.
I`m wondering if the ASM has been parsed correctly, as instances 0 and 1 are not the same as all the others?
here:
;Set up the assembler options (Chip type, clock source, other bits and pieces)
LIST p=16C54, r=DEC
#include <P16C5X.inc>
__CONFIG _RC_OSC & _WDT_ON
;Vectors
;Start of program memory page 0
ORG 0
BASPROGRAMSTART
;Call initialisation routines
call INITSYS
;Automatic pin direction setting
clrw
tris PORTB
;Start of the main program
movlw 255
tris A
clrw
tris B
START
movf PORTA,F
btfss STATUS, Z
goto ENDIF1
movlw 126
movwf PORTB
ENDIF1
decf PORTA,W
btfss STATUS, Z
goto ENDIF2
movlw 48
movwf PORTB
ENDIF2
movlw 2
subwf PORTA,W
btfss STATUS, Z
goto ENDIF3
movlw 109
movwf PORTB
etc….
I would have expected all instances to have been the same only with differing values, and yet the 1`st 2 clearly are different from the rest for some reason?
this May be the problem, I have no idea?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Sure sounds like a WDT timeout, and chip reset, although the 250 ms sounds a bit long. If the WDT is enabled, it should be cleared with the "asm clrwdt" command somewhere in the code.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You`re a Genius! thank you!
turns out that even though the WDT is disabled in GCBasic, the actual Programmer s/ware re-enables it, and also defaults to the 16c57 chip, so I turned it off in That prog as well, blasted another chip and it`s working exactly as it should do :)
Thanks again! :D
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
First of all I would like to compliment the team responsible for this program, GCBASIC is Fantastic!
I DL`d it last night, opened it this morning and wrote a program (that works) before I`d finished my 1`st cup of coffee! :)
Most of it is quite intuitive, and I`m all for keeping stuff simple.
I do have a small problem though, and I`m not entirely sure what`s causing it though?
I`v knocked up a quick prog to turn 4 bit binary into 7 segment HEX display.
and although it works, for some reason the display seems to blink once every 3-4 seconds for no reason I can see?
the display will update to the new binary number faster than this blink rate, so I don`t think it`s a slow prog loop.
I`v altered the uC speed from 1MHz to 4MHz (no change) WDT On and Off (no change) i`m using RC for the clock.
so I`m totally at a loss here?
the code`s using GOTO loops that have every possibility covered (there`s only 16 of them anyway), so I don`t think it`s escaping the LOOP.
my code is as follows:
;Chip Settings
#chip 16C54,1
#config WDT=ON, OSC=RC
Dir a In
Dir b Out
start:
If porta=0x0 then
goto zero
end if
if porta=0x1 then
goto one
end if
if porta=0x2 then
goto two
end if
if porta=0x3 then
goto three
end if
if porta=0x4 then
goto four
end if
if porta=0x5 then
goto five
end if
if porta=0x6 then
goto six
end if
if porta=0x7 then
goto seven
end if
if porta=0x8 then
goto eight
end if
if porta=0x9 then
goto nine
end if
if porta=0xa then
goto ten
end if
if porta=0xb then
goto eleven
end if
if porta=0xc then
goto twelve
end if
if porta=0xd then
goto thirteen
end if
if porta=0xe then
goto fourteen
end if
if porta=0xf then
goto fifteen
end if
zero:
portb= b'01111110'
goto start:
one:
portb= b'00110000'
goto start:
two:
portb= b'01101101'
goto start:
three:
portb= b'01111001'
goto start:
four:
portb= b'00110011'
goto start:
five:
portb= b'01011011'
goto start:
six:
portb= b'01011111'
goto start:
seven:
portb= b'01110000'
goto start:
eight:
portb= b'01111111'
goto start:
nine:
portb= b'01110011'
goto start:
ten:
portb= b'01110111'
goto start:
eleven:
portb= b'00011111'
goto start:
twelve:
portb= b'01001110'
goto start:
thirteen:
portb= b'00111101'
goto start:
fourteen:
portb= b'01001111'
goto start:
fifteen:
portb= b'01000111'
goto start:
a Very simple State Machine in procedure, and yet I cannot see what I have done wrong to make it blink at a 3 to 4 Hz rate?
Anyone?
Hi ,
There are many possibilities to obtain what you mean .
You can try with "select case" command and subs
;Chip Settings
#chip 16C54,1
#config WDT=OFF, OSC=RC
Dir a In
Dir b Out
do
select case porta
case 0
zero
case 1
one
case 2
three
.
.
.
case 15
fifteen
end select
wait 30ms 'It's not necessary but you can enter another delay in order to obtain the max of your display
loop
sub zero
portb= b'01111110'
end sub
sub one
portb= b'00110000'
end sub
sub two
portb= b'01101101'
end sub
.
.
.
sub fifteen
portb= b'01000111'
end sub
Thanks, I`v refined the code a little bit more since, and may use the CASE or lookup tables latter, but I still have the same problem with This code too:
;Chip Settings
#chip 16C54,1
#config WDT=ON, OSC=RC
Dir a In
Dir b Out
start:
if porta=0x0 then
portb= b'01111110'
end if
if porta=0x1 then
portb= b'00110000'
end if
if porta=0x2 then
portb= b'01101101'
end if
if porta=0x3 then
portb= b'01111001'
end if
if porta=0x4 then
portb= b'00110011'
end if
if porta=0x5 then
portb= b'01011011'
end if
if porta=0x6 then
portb= b'01011111'
end if
if porta=0x7 then
portb= b'01110000'
end if
if porta=0x8 then
portb= b'01111111'
end if
if porta=0x9 then
portb= b'01110011'
end if
if porta=0xa then
portb= b'01110111'
end if
if porta=0xb then
portb= b'00011111'
end if
if porta=0xc then
portb= b'01001110'
end if
if porta=0xd then
portb= b'00111101'
end if
if porta=0xe then
portb= b'01001111'
end if
if porta=0xf then
portb= b'01000111'
end if
goto start:
it all works perfectly apart from the display blinking off every 3-4 seconds for about 250mS, but during this time, I can change numbers quite easily, so it`s not the program loop.
there has to be something else.
I`m wondering if the ASM has been parsed correctly, as instances 0 and 1 are not the same as all the others?
here:
;Set up the assembler options (Chip type, clock source, other bits and pieces)
LIST p=16C54, r=DEC
#include <P16C5X.inc>
__CONFIG _RC_OSC & _WDT_ON
;********************************************************************************
;Vectors
;Start of program memory page 0
ORG 0
BASPROGRAMSTART
;Call initialisation routines
call INITSYS
;Automatic pin direction setting
clrw
tris PORTB
;Start of the main program
movlw 255
tris A
clrw
tris B
START
movf PORTA,F
btfss STATUS, Z
goto ENDIF1
movlw 126
movwf PORTB
ENDIF1
decf PORTA,W
btfss STATUS, Z
goto ENDIF2
movlw 48
movwf PORTB
ENDIF2
movlw 2
subwf PORTA,W
btfss STATUS, Z
goto ENDIF3
movlw 109
movwf PORTB
etc….
I would have expected all instances to have been the same only with differing values, and yet the 1`st 2 clearly are different from the rest for some reason?
this May be the problem, I have no idea?
Sure sounds like a WDT timeout, and chip reset, although the 250 ms sounds a bit long. If the WDT is enabled, it should be cleared with the "asm clrwdt" command somewhere in the code.
You`re a Genius! thank you!
turns out that even though the WDT is disabled in GCBasic, the actual Programmer s/ware re-enables it, and also defaults to the 16c57 chip, so I turned it off in That prog as well, blasted another chip and it`s working exactly as it should do :)
Thanks again! :D