PDA

View Full Version : 16f84A to 16f628A



dovegroup
- 23rd June 2012, 21:41
Hi friends
I am new user in picbasic
And need help, for the transformation of this code to work on 16F628A instead of the 16F84A



@ device PIC16F84A, HS_OSC, WDT_OFF, PWRT_ON, PROTECT_OFF
TrisA = %00000000
PortA = %00000000
TrisB = %00000001
PortB = %00000000

Digit Var Byte
Time Var Word
Tcon Con 245
Time = Tcon
Imp Var Word
Imp = 0
RPM Var Word
RPM = 0
OPTION_REG = %10000011
TMR0=5
INTCON = %10110000
Pause 1000
' ------------------------- [ ---------- ] -------------------------

PortB = $7e '-
PortA.0 = 0: PortA.1 = 0: PortA.2 = 1
Pause 1000
PortB = $7e '-
PortA.0 = 0: PortA.1 = 1: PortA.2 = 0
Pause 1000
PortB = $7e '-
PortA.0 = 1: PortA.1 = 0: PortA.2 = 0
Pause 1000
' ------------------------- [ Interrupt ] -------------------------
On Interrupt Goto myint
' ------------------------- [ Main ] -------------------------
Main:

Digit = RPM Dig 0
PortA.0 = 1: PortA.1 = 0: PortA.2 = 0
GoSub Look
Pause 4
PortB = $FE

Digit = RPM Dig 1
PortA.0 = 0: PortA.1 = 1: PortA.2 = 0
GoSub Look
Pause 4
PortB = $FE

if RPM < 100 then
Pauseus 300
Goto Main
endif

Digit = RPM Dig 2
PortA.0 = 0: PortA.1 = 0: PortA.2 = 1
GoSub Look
Pause 4
PortB = $FE

Goto Main
' ----------------------- [-------------- ] -----------------------

Disable
Myint:

if intcon.1=1 then
Imp = Imp + 1
INTCON.1 = 0
endif


if intcon.2=1 then
Time = Time - 1
if Time = 0 then
Time = Tcon
RPM = Imp * 60 / 10
Imp = 0
endif
TMR0=5
intcon.2=0
endif

Resume
Enable
' --------------------------- [ ------- ] ---------------------------
Look:
LookUp Digit, [$80, $F2, $48, $60, $32, $24, $04, $F0, $00, $20], PortB
Return
' ------------------------- [ ----------- ] -------------------------
End

grahamg
- 24th June 2012, 18:04
Change first line to @ Device PIC16f628A HS_OSC, WDT_OFF, PWRTE_ON, CP_OFF
That in theory is all that should be needed.

Archangel
- 25th June 2012, 08:10
Change first line to @ Device PIC16f628A HS_OSC, WDT_OFF, PWRTE_ON, CP_OFF
That in theory is all that should be needed.
nope, 16f628 has comparators too add cmcon = 7

dovegroup
- 25th June 2012, 17:51
I made the changes and work henceforth in 16F628
I thank you for the precious help

dovegroup
- 27th June 2012, 14:52
I made an addition to the code
The PortA.3 working properly, the PortA.4 but did not work always remains at a low level
What I make error, please help




@ device PIC16F84A, HS_OSC, WDT_OFF, PWRT_ON, PROTECT_OFF
TrisA = %00000000
PortA = %00000000
TrisB = %00000001
PortB = %00000000

Digit Var Byte
Time Var Word
Tcon Con 245
Time = Tcon
Imp Var Word
Imp = 0
RPM Var Word
RPM = 0
OPTION_REG = %10000011
TMR0=5
INTCON = %10110000
Pause 1000
' ------------------------- [ ---------- ] -------------------------

PortB = $7e '-
PortA.0 = 0: PortA.1 = 0: PortA.2 = 1
Pause 1000
PortB = $7e '-
PortA.0 = 0: PortA.1 = 1: PortA.2 = 0
Pause 1000
PortB = $7e '-
PortA.0 = 1: PortA.1 = 0: PortA.2 = 0
Pause 1000
' ------------------------- [ Interrupt ] -------------------------
On Interrupt Goto myint
' ------------------------- [ Main ] -------------------------
Main:

Digit = RPM Dig 0
PortA.0 = 1: PortA.1 = 0: PortA.2 = 0
GoSub Look
Pause 4
PortB = $FE

Digit = RPM Dig 1
PortA.0 = 0: PortA.1 = 1: PortA.2 = 0
GoSub Look
Pause 4
PortB = $FE

if RPM < 100 then
Pauseus 300
Goto Main
endif

Digit = RPM Dig 2
PortA.0 = 0: PortA.1 = 0: PortA.2 = 1
GoSub Look
Pause 4
PortB = $FE

' ----------------------- [ HIGH RPM ] -----------------------
if RPM >= 60 then
high PortA.3
else
low PortA.3
endif

if RPM >= 70 then
high PortA.4
else
low PortA.4
endif

Goto Main
' ----------------------- [-------------- ] -----------------------

Disable
Myint:

if intcon.1=1 then
Imp = Imp + 1
INTCON.1 = 0
endif


if intcon.2=1 then
Time = Time - 1
if Time = 0 then
Time = Tcon
RPM = Imp * 60 / 10
Imp = 0
endif
TMR0=5
intcon.2=0
endif

Resume
Enable
' --------------------------- [ ------- ] ---------------------------
Look:
LookUp Digit, [$80, $F2, $48, $60, $32, $24, $04, $F0, $00, $20], PortB
Return
' ------------------------- [ ----------- ] -------------------------
End

grahamg
- 27th June 2012, 16:33
You have not added Cmcon=7. Put it at the start of the program

dovegroup
- 27th June 2012, 16:41
grahamg Yes I added cmcon = 7

*******************************
@ device PIC16F628A, HS_OSC, WDT_OFF, PWRT_ON, PROTECT_OFF
TrisA = %00000000
PortA = %00000000
TrisB = %00000001
PortB = %00000000

cmcon = 7
Digit Var Byte
Time Var Word
Tcon Con 245
Time = Tcon
Imp Var Word
Imp = 0
RPM Var Word
RPM = 0
OPTION_REG = %10000011
TMR0=5
INTCON = %10110000
Pause 1000

EEPROM 80,[83,46,84,32,69,108,101,99,116,114,111,110,105,99,1 15]
' ------------------------- [ ---------- ] -------------------------


http://i1261.photobucket.com/albums/ii581/Ivan-cym/ERR.png

aratti
- 27th June 2012, 17:04
RA4 is an open collector pin so it will not turn from zero to 5 volts as all the digital pins.

If all you need is to turn your led on & off, then connect your 330 ohms resistor to 5 volts and RA4 pin to junction from led and 330 ohms resistor.

Remember then when pin is on your led will be off.

Cheers

Al.

dovegroup
- 27th June 2012, 18:33
Friend aratti yes you have absolute right
Now works also the PortA.4 yessssssssssssssssssss

Thank you very much

http://i1261.photobucket.com/albums/ii581/Ivan-cym/WORK.png