Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

16f628A ---> 16f88 I/P

Status
Not open for further replies.

SwingeyP

Member
Hello again,

Can anyone help me with this one please.

I have a simple LCD hello world code runs fine on a 16f628a but won't run on a 16f88.

Pin assignments are the same - internal osc - configuration word the same- fine in simulation

What am I doing wrong?

Regards - Paul

Code:
'Define SIMULATION_WAITMS_VALUE = 1

Define CONF_WORD = 0x3f50  'Internal Oscillator'
Define CLOCK_FREQUENCY = 4
AllDigital

'define the ADC stuff
'Define ADC_CLOCK = 3  'default value is 3
'Define ADC_SAMPLEUS = 10  'default value is 20


'Define the comms for the LCD display.
Define LCD_LINES = 4
Define LCD_CHARS = 20
Define LCD_BITS = 4
Define LCD_DREG = PORTB
Define LCD_DBIT = 4  'Use the high order bits'
Define LCD_RSREG = PORTA
Define LCD_RSBIT = 2
Define LCD_EREG = PORTA
Define LCD_EBIT = 0
Define LCD_RWREG = PORTA
Define LCD_RWBIT = 1
Define LCD_READ_BUSY_FLAG = 1


Define LCD_COMMANDUS = 5000  'delay after LCDCMDOUT, default value is 5000
Define LCD_DATAUS = 100  'delay after LCDOUT, default value is 100
Define LCD_INITMS = 20


'--- Variables
'Dim adc1 As Word




Lcdinit LcdCurBlink
Lcdcmdout LcdClear

WaitMs 500  'Give everything time to power up 2 seconds?



'adcon0 = 0xc0  'set A/D conversion clock to internal source

'adcon1 = 1  'set PORTA pins as analog inputs
'High adcon0.adon  'turn on A/D converter module

loop:
'Adcin 3, adc1
	Lcdcmdout LcdLine1Pos(1)
	Lcdout "Hello "
Goto loop
 
hi Paul,
Have downloaded it, will let you know.

E.
 
All the ADC stuff is commented out at present. I can't get past the first hurdle yet :-(

hi Pauld,
It displays Hello for me OK.

Ref the ADC part , is that your problem.??

E.

EDIT:
Which simulator are you using? I use Oshonsoft.
 
Last edited:
Hi Eric. Runs a dream in simulation with OSHON as does the 628a version.

I have the 628 version on a chip. Place on the board and hey presto HELLO
the f88 version on the same board two black lines. It's almost as if the pic isn't runing.

The board is the one you wired up for me - I still use it now. As the 628 is fine it's not the board.

The ADC stuff will come later just reading a value from a temperature sensor but I can't get the 'hello' working yet.

Regards - Paul
 
hi,
Ok,

BTW you need

ANSEL.ANS3 = 1 to set the ADC3 as analog

I will look further at the LCD problem.

E.
 
hi Paul,
Your CONFIG is set wrong, look at this image.

EDIT:

Ignore that!! the Oshonsoft says otherwise...
 

Attachments

  • AAesp04.gif
    AAesp04.gif
    64 KB · Views: 483
Hi Eric,

I tried the config using MPLAB configuration tool but nothing seemed to work.

hi,
Have you set the OSCCON register for a 4MHz clock.??

If you compile in Oshonsoft Basic and you have defined the clock as 4MHz it should set the OSCCON reg for you.??

Remind me, how you are you using the /MCLR pin ??
E.
 
Define CONF_WORD = 0x3f50 'Internal Oscillator'
Define CLOCK_FREQUENCY = 4
AllDigital


Im not using the /mclr pin at all

Regards - Paul
 
hi,
I have got the asm file created in Oshonsoft running in MPLAB, added a suitable header.

With the CONFIG bits to 0x35f0.

I cannot see in the assembled Oshonsoft 'asm' any reference to the OSCCON setting for 4MHz.???

Try setting OSCCON in the Oshonsoft Basic program.

E.
 
Thanks Eric,

I would never have found that one!

Working a treat.... with Temperature reading (although not calibrated)

Regards - Paul


Code:
'- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
'LM35 Temperature sensor written by paul swingewood
'April 2013   - PIC 16F88
'--------------------------------------------------------------------------

'Define SIMULATION_WAITMS_VALUE = 1

Define CONF_WORD = 0x3f50  'Internal Oscillator'
'Define CONF_WORD_2 = 0x3ffc
Define CLOCK_FREQUENCY = 4
OSCCON = %01101000

AllDigital

'define the ADC stuff
Define ADC_CLOCK = 3  'default value is 3
Define ADC_SAMPLEUS = 10  'default value is 20


'Define the comms for the LCD display.
Define LCD_LINES = 4
Define LCD_CHARS = 20
Define LCD_BITS = 4
Define LCD_DREG = PORTB
Define LCD_DBIT = 4  'Use the high order bits'
Define LCD_RSREG = PORTA
Define LCD_RSBIT = 2
Define LCD_EREG = PORTA
Define LCD_EBIT = 0
Define LCD_RWREG = PORTA
Define LCD_RWBIT = 1
Define LCD_READ_BUSY_FLAG = 1


Define LCD_COMMANDUS = 5000  'delay after LCDCMDOUT, default value is 5000
Define LCD_DATAUS = 100  'delay after LCDOUT, default value is 100
Define LCD_INITMS = 20


'--- Variables
Dim adc1 As Word




Lcdinit LcdCurBlink
Lcdcmdout LcdClear

WaitMs 500  'Give everything time to power up 2 seconds?



ADCON0 = 0xc0  'set A/D conversion clock to internal source

ADCON1 = 1  'set PORTA pins as analog inputs
High ADCON0.ADON  'turn on A/D converter module
ANSEL.ANS3 = 1  'To set the adc3 As analog



loop:
Adcin 3, adc1
	Lcdcmdout LcdLine1Pos(1)
	Lcdout "temp ", #adc1, "   "
Goto loop
 
hi Paul,
This simple program will be helpful for formatting the ADC temperature reading, just use the sections to suit your project.

E.

Code:
'04 Feb 2010 Forum



Define SIMULATION_WAITMS_VALUE = 1  'make this =0 for programming a PIC
'------------------------------------
'setup temp variables
Dim ascbfr4 As Byte
Dim ascbfr3 As Byte
Dim ascbfr2 As Byte
Dim ascbfr1 As Byte
Dim ascbfr0 As Byte

Dim temp3 As Word
Dim binval As Word

Dim volt0 As Word
Dim vref1 As Word

Dim intrcnt As Byte
Dim adcavg1 As Word

'''''''''''''''''''
T1CON.T1OSCEN = 1
T1CON.TMR1CS = 0
T1CON.TMR1ON = 1
T1CON.T1CKPS0 = 1  'tmr1 prescaler /256 gives a 8 microsec clock period
T1CON.T1CKPS1 = 1

TMR1H = 0xcf  'FFFF - CF2C = 30D3 == 12500 * 8 = ~ 0.1 sec/intr
TMR1L = 0x2c

INTCON.GIE = 1
INTCON.PEIE = 1

PIE1.TMR1IE = 1
PIR1.TMR1IF = 0
'''''''''''''''''''''''''''''''

adcon0 = %01000001  'fosc/8
adcon1 = %10000100  'Dis clk div,,,an0 > an3 analaog rest dig

TRISA = %00001111
TRISB = %00000001  'reserve portb.0 for ext interrupts, if required
trisc = %11111111
'-----------------------------------------------------

Lcdinit
Enable  'enable interrupts

main0:
Lcdcmdout LcdClear

main:
'loop
If intrcnt > 4 Then  'count the 0.1sec intrs, get 5 values, average and display every 0.5s
''Break
intrcnt = 0
binval = adcavg1 / 5  '''volt0  'rename for the bin2asc subr
Gosub bin2asc

Lcdcmdout LcdLine1Home
Lcdout "Percent: ", ascbfr3, ascbfr2, ascbfr1, ".", ascbfr0, "%"

binval = adcavg1 / 25  ''volt0 / 5
Gosub bin2asc

Lcdcmdout LcdLine2Home
Lcdout "Val:"ascbfr2, ascbfr1, ".", ascbfr0

adcavg1 = 0

If volt0 > vref1 Or volt0 = vref1 Then
Lcdcmdout LcdLine2Pos(11)
Lcdout "V0 OK "
Else
Lcdcmdout LcdLine2Pos(11)
Lcdout "V0 Low"
Endif

Endif

Goto main

End                                               
On Interrupt
Save System

PIR1.TMR1IF = 0

TMR1H = 0xcf
TMR1L = 0x2c

intrcnt = intrcnt + 1

Gosub readadc

adcavg1 = adcavg1 + volt0

Resume                                            

'scale the 5V input to 4.88v using a resistive divider
readadc:
'read adc word
Adcin 0, volt0
Adcin 1, vref1  'this is the compare to voltage
Return                                            



'you can convert any binary value from 0000h to fffFh to 0000 to 65535 decimal
'just name the binary word as binval and call this subr and the ASCII
'result will be in ascbfr4,3,2,1,0, ready for your LCD or UART
'just pop the DP in the output to the LCD [as shown above]

bin2asc:
'ascbfr4 = binval / 10000' add these 4 lines for 16 bit conv
'temp3 = binval Mod 10000

'ascbfr3 = temp3 / 1000
'temp3 = binval Mod 1000

ascbfr3 = binval / 1000  'delete for 16 bit conv
temp3 = binval Mod 1000  'delete for 16 bit

ascbfr2 = temp3 / 100
temp3 = temp3 Mod 100

ascbfr1 = temp3 / 10
ascbfr0 = temp3 Mod 10
'results are BCD so
'convert to ASCII for LCD or UART
ascbfr4 = ascbfr4 Or 0x30
ascbfr3 = ascbfr3 Or 0x30
ascbfr2 = ascbfr2 Or 0x30
ascbfr1 = ascbfr1 Or 0x30
ascbfr0 = ascbfr0 Or 0x30
Return
 
Status
Not open for further replies.

Latest threads

Back
Top