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.

Oshonsoft users?

Status
Not open for further replies.
ahh i see now... will do my best to cal it to 4.88V then!!!

what would i need to modify on the code to make it run on a 0-20 scale to 1d.p instead of 0-100 (ie not %age?)

hi,
You could divide the 1000 count by 5 [200] or by 50 [20].

Its quite easy to do this in Oshonsoft Basic.

My Forum Blog external modules will help with the ADC input.

NB: use a 5K pot on the 5V signal to reduce to 4.88V for the ADC input.
 
Last edited:
hi,
You could divide the 1000 count by 5 [200] or by 50 [20].

Its quite easy to do this in Oshonsoft Basic.

My Forum Blog external modules will help with the ADC input.

NB: use a 5K pot on the 5V signal to reduce to 4.88V for the ADC input.
brilliant, like i said im looking forward to try and get this up and running tomorrow... hopefully there wont be too much "real" work on so i can get a good hour or so with my hardware and OS.

will keep you posted. Thanks!!!
 
hi guys... found out that all my capacitor had decided to destroy itself over the last few days so spent time fixing it instead of testing it...

anyhow, hardware issues asside...

i am struggling to get the 0-20L to display on the seconds line. i can get it to display something but i just cannot fall upon the correct algorithm to get it to display 0-20 to 1 d.p...

i think it may have something to do with my use of bytes and words but don't really understand how to achieve this... (if only college had taught us something useful back in the day :-(

thanks guys...
 
Try this:

Code:
Define LCD_BITS = 4
Define LCD_DREG = PORTB
Define LCD_DBIT = 4
Define LCD_RSREG = PORTA
Define LCD_RSBIT = 4
Define LCD_EREG = PORTA
Define LCD_EBIT = 5

Define SIMULATION_WAITMS_VALUE = 1
'------------------------------------
'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 val0 As Word


ADCON0 = %01000001  'adcchan0
ADCON1 = %10001011  'Dis clk div,,,an0 > an3 analaog rest dig

TRISA = %00000001
TRISB = %11111111  'all inputs on portb
TRISC = %11111111
'-----------------------------------------------------

Lcdinit

main0:
Lcdcmdout LcdClear

main:
Gosub readadc
Goto main

End                                               

'scale the 5V input to 4.88v using a resistive divider
readadc:
'read adc word
Adcin 0, val0

binval = val0  'rename for the bin2asc subr
Gosub bin2asc

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


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 / 500  'delete for 16 bit conv
temp3 = binval Mod 500  'delete for 16 bit

ascbfr2 = temp3 / 50
temp3 = temp3 Mod 50

'ascbfr1 = temp3 / 10
ascbfr1 = temp3 Mod 5
'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

Wilksey
 
Try this:

Code:
Define LCD_BITS = 4
Define LCD_DREG = PORTB
Define LCD_DBIT = 4
Define LCD_RSREG = PORTA
Define LCD_RSBIT = 4
Define LCD_EREG = PORTA
Define LCD_EBIT = 5

Define SIMULATION_WAITMS_VALUE = 1
'------------------------------------
'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 val0 As Word


ADCON0 = %01000001  'adcchan0
ADCON1 = %10001011  'Dis clk div,,,an0 > an3 analaog rest dig

TRISA = %00000001
TRISB = %11111111  'all inputs on portb
TRISC = %11111111
'-----------------------------------------------------

Lcdinit

main0:
Lcdcmdout LcdClear

main:
Gosub readadc
Goto main

End                                               

'scale the 5V input to 4.88v using a resistive divider
readadc:
'read adc word
Adcin 0, val0

binval = val0  'rename for the bin2asc subr
Gosub bin2asc

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


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 / 500  'delete for 16 bit conv
temp3 = binval Mod 500  'delete for 16 bit

ascbfr2 = temp3 / 50
temp3 = temp3 Mod 50

'ascbfr1 = temp3 / 10
ascbfr1 = temp3 Mod 5
'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

Wilksey

thanks for the reply wilksey but i managed to get the LCD to work (much trial and error until a small eureka moment struck me)...

my problem is more with the mathematics and code of getting the 0.0 to 20.0 on the 2nd line... at the moment stuff is displayed but the numbers are not correct... i think it is my confusion with bytes and words and the MOD function (not exclusively those unfortunately :-(
 
thanks for the reply wilksey but i managed to get the LCD to work (much trial and error until a small eureka moment struck me)...

my problem is more with the mathematics and code of getting the 0.0 to 20.0 on the 2nd line... at the moment stuff is displayed but the numbers are not correct... i think it is my confusion with bytes and words and the MOD function (not exclusively those unfortunately :-(

hi Jim,
Divide the 1000 counts == 4.88v by 5 to give a value of 200

Code:
'scale the 5V input to 4.88v using a resistive divider
readadc:
'read adc word
Adcin 0, val0

binval = val0  'rename for the bin2asc subr
[COLOR="Blue"]
binval =binval/5 ' reduces 1000 to 200[/COLOR]

Gosub bin2asc

Lcdcmdout LcdLine1Home
Lcdout "Value[COLOR="Blue"][/COLOR]: ", ascbfr3, ascbfr2, ".", ascbfr1


Return
 
hi Jim,
Divide the 1000 counts == 4.88v by 5 to give a value of 200

Code:
'scale the 5V input to 4.88v using a resistive divider
readadc:
'read adc word
Adcin 0, val0

binval = val0  'rename for the bin2asc subr
[COLOR="Blue"]
binval =binval/5 ' reduces 1000 to 200[/COLOR]

Gosub bin2asc

Lcdcmdout LcdLine1Home
Lcdout "Value[COLOR="Blue"][/COLOR]: ", ascbfr3, ascbfr2, ".", ascbfr1


Return

i thought i tried that (i worked it out in pen a paper what i would do in real life and tried to implement that in code, is this a good way of doing it for future referance?)...

anyhow, probably did something silly...

will try that out today at lunchtime and then see what other things i can try and implement...

cannot thank you enough right now...
 
hi Jim,
If you want to display the 100.0% on LCD line #1 and the 20.0 value on line #2 use this program.

Code:
'04Feb 2010 Forum

Define LCD_BITS = 4
Define LCD_DREG = PORTB
Define LCD_DBIT = 4
Define LCD_RSREG = PORTA
Define LCD_RSBIT = 4
Define LCD_EREG = PORTA
Define LCD_EBIT = 5

Define SIMULATION_WAITMS_VALUE = 1
'------------------------------------
'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 val0 As Word


ADCON0 = %01000001  'adcchan0
ADCON1 = %10001011  'Dis clk div,,,an0 > an3 analaog rest dig

TRISA = %00000001
TRISB = %11111111  'all inputs on portb
TRISC = %11111111
'-----------------------------------------------------

Lcdinit

main0:
Lcdcmdout LcdClear

main:
Gosub readadc
Goto main

End                                               

'scale the 5V input to 4.88v using a resistive divider
readadc:
'read adc word
Adcin 0, val0

binval = val0  'rename for the bin2asc subr
Gosub bin2asc

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

binval = val0 / 5
Gosub bin2asc

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

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
AAesp01.gif
 
Last edited:
finally got my hardware together and working, programmed the PIC and after some hours of swearing and debugging got it all together...

i have a few more code queries but i am going to have a good stab at implementing them myself tonight before bothering you with them...

thanks...
 
hi all... had a play last night with some minor successes.. am finally starting to understand why it works rather than just praying and see :)

anyhow, using the compiler is it possible to:

1: take an average value every half a second or so to stop the screen flicking between values like it is now?
2: have a message appear when a certain value is reached.
3: an interupt or response to a switch or something which causes the LCD display to completely blacken (to prove it is working) for a second or so then return to normal service?

my aim for the next 2 or 3 days is to get it doing this... hopefully i can dedicate some real time to it again...
 
hi all... had a play last night with some minor successes.. am finally starting to understand why it works rather than just praying and see :)

anyhow, using the compiler is it possible to:

1: take an average value every half a second or so to stop the screen flicking between values like it is now?
2: have a message appear when a certain value is reached.
3: an interupt or response to a switch or something which causes the LCD display to completely blacken (to prove it is working) for a second or so then return to normal service?

my aim for the next 2 or 3 days is to get it doing this... hopefully i can dedicate some real time to it again...

hi Jim,
Yes it possible to do the functions that you have listed.:)
 
hi all.... hope you are all doing OK...

ive been playing with my hardware again and now the range i have to operate in has changed completely... the range is now 0.5 to 3.71V... these are my final values (hopefully)

so essential 0.5V has to be 0.0L and 3.7V has to be my 20L point... and i'm up a creek without a paddle on how to solve this problem...

i know the binary values are 102 and 757 respectively but dont know how to work that in...

as usual all help will be appreciated more than the internet can ever show :)

Thanks!!!
 
Last edited:
oh, will me putting a copy of the basic code im using up make things a little easier?

hi Jim,
I would like to see the code, I have also done more work on the code, just in case you came back.:)
 
Ok, here is the last stable working version i had (note: i have changed the values to abc just because it was quicker to write and i kept messing up before :-(

i have been messing about with it since (with minimal success, like i said, ive been playing with hardware) but this is it...

Define ADC_CLOCK = 3 'default value is 3
Define ADC_SAMPLEUS = 10 'default value is 20
Define LCD_BITS = 8 'allowed values are 4 and 8 - the number of data interface lines
Define LCD_DREG = PORTD
Define LCD_DBIT = 0 '0 or 4 for 4-bit interface, ignored for 8-bit interface
Define LCD_RSREG = PORTC
Define LCD_RSBIT = 0
Define LCD_EREG = PORTC
Define LCD_EBIT = 1
Define LCD_RWREG = 0 'set to 0 if not used, 0 is default
Define LCD_RWBIT = 0 'set to 0 if not used, 0 is default
Define LCD_COMMANDUS = 100 'delay after LCDCMDOUT, default value is 5000
Define LCD_DATAUS = 10 'delay after LCDOUT, default value is 50
Define LCD_INITMS = 1 'delay used by LCDINIT, default value is 100
'the last three Define directives set the values suitable for simulation; they should be omitted for a real device
'------------------------------------
'setup temp variables
Dim abc4 As Byte
Dim abc3 As Byte
Dim abc2 As Byte
Dim abc1 As Byte
Dim abc0 As Byte


Dim temp3 As Word
Dim binval As Word

Dim val0 As Word


'ADCON0 = %01000001 'adcchan0
'ADCON1 = %10001011 'Dis clk div,,,an0 > an3 analaog rest dig

TRISA = %00000001
TRISB = %11111111 'all inputs on portb
TRISC = %11111100

'TRISD = 0x00
'TRISE.2 = 0
'TRISE.0 = 0



'-----------------------------------------------------

Lcdinit
Lcddefchar 0, 31, 31, 31, 31, 31, 31, 31, 31
Lcddefchar 1, %00011111, %00011111, %00011111, %00011111, %00011111, %00011111, %00011111, %00011111
Lcdout 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
Lcdcmdout LcdLine2Home
Lcdout 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
WaitMs 1000
Lcdcmdout LcdHome
Lcdout "**Initialising**"
Lcdcmdout LcdLine2Home
Lcdout "*****FLIPS******"
WaitMs 750
Lcdcmdout LcdHome
Lcdout " PLEASE "
Lcdcmdout LcdLine2Home
Lcdout " WAIT "
WaitMs 750

main0:
Lcdcmdout LcdClear

main:
Gosub readadc
Goto main

End

'scale the 5V input to 4.88v using a resistive divider
readadc:
'read adc word
Adcin 0, val0

binval = val0 'rename for the bin2asc subr
Gosub bin2asc

Lcdcmdout LcdHome
Lcdout "Percent: ", abc3, abc2, abc1, ".", abc0, "%"

'scale the 5V input to 4.88v using a resistive divider
readadc:
'read adc word
Adcin 0, val0

binval = val0 'rename for the bin2asc subr

binval = binval / 5 'reduces 1000 to 200

Gosub bin2asc

Lcdcmdout LcdLine2Home
Lcdout "Volume: ", abc2, abc1, ".", abc0, "L"

Return

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

'abc3 = temp3 / 1000
'temp3 = binval Mod 1000

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

abc2 = temp3 / 100
temp3 = temp3 Mod 100

abc1 = temp3 / 10
abc0 = temp3 Mod 10

abc4 = abc4 Or 0x30
abc3 = abc3 Or 0x30
abc2 = abc2 Or 0x30
abc1 = abc1 Or 0x30
abc0 = abc0 Or 0x30
WaitMs 250


Return








and ive only got 6 hours of my evaluation OS left :mad:
 
Last edited:
hi Jim,
Look at this edited version of your basic program, change the *.txt extension to *.bas

When you use the Oshonsoft Sim add this line near the top of your program.
Define SIMULATION_WAITMS_VALUE = 1 'make this =0 for programming a PIC

This will enable the sim run much faster as the 'delays' are skipped.

You need to trim the 102 and 757 values slightly to match the 4.88v [5V] == 1000 adc counts.

What happened to the averaging and interrupt features that you posted about earlier.????

Regards
 

Attachments

  • jimown1m.txt
    3.4 KB · Views: 389
morning eric... thanks, will have a look at those as soon as i get back from work (half day is always nice!)

like i said that was the last stable version i had... i have been trying to get the interrupt and averaging features to work but with no success... when i switched the real lcd on it was refreshing so fast that most of the values couldn't be seen so i cheated and added the waitms 250 command at the end... this isn't the best solution...

as for interupts... no luck whatsoever with those so far and im running out of evaluation perid time, so im writing in notepad then experimenting... not the most ideal situation but still, beggers cannot be choosers in this case...

you mind me asking what your profession is/was or has micros just become a hobby of yours over the years?
 
you mind me asking what your profession is/was or has micros just become a hobby of yours over the years?

hi Jim,
Try this program, it samples every 0.1sec and displays the average of 5 samples every 0.5sec.

Use the remmed out values for BOTH the TIMER1 values when you program a PIC.
TMR1H = 0xfe ''0xcf 'FFFF - CF2C = 30D3 == 12500 * 8 = ~ 0.1 sec/intr
TMR1L = 0xfe ''0x2c

NOTE: these TIMER1 values are for a 4 MHz xtal.!

also make this =0
Define SIMULATION_WAITMS_VALUE = 1 'make this =0 for programming a PIC

Convert the LCD PORT pins to suit your project.

For my details look at my forum profile.;)
 

Attachments

  • jim2.txt
    3.2 KB · Views: 379
Last edited:
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top