SparkyChem
Member level 3
- Joined
- Apr 22, 2010
- Messages
- 57
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,286
- Location
- Lima, Peru
- Activity points
- 2,084
program F676_exp
' Declarations section
'******************************************************
dim LCD_RS as sbit at RC4_bit ' Lcd
LCD_EN as sbit at RC5_bit
LCD_D4 as sbit at RC3_bit
LCD_D5 as sbit at RC2_bit
LCD_D6 as sbit at RC1_bit
LCD_D7 as sbit at RC0_bit
LCD_RS_Direction as sbit at TRISC4_bit
LCD_EN_Direction as sbit at TRISC5_bit
LCD_D4_Direction as sbit at TRISC3_bit
LCD_D5_Direction as sbit at TRISC2_bit
LCD_D6_Direction as sbit at TRISC1_bit
LCD_D7_Direction as sbit at TRISC0_bit ' LCD
dim text as string [16] ' text string
dim ch, adc_rd as word ' ch, adc_rd word
dim tlong as longword ' tlong, longword
sub procedure settings
CMCON=7
ANSEL=%00000001
ADCON1=%00110000
ADCON0=%10000001
TRISA=%000001
INTCON = 0 ' all interrupts disabled
TRISC = 0 ' PORTC is output
end sub
main:
' Main program
settings
Lcd_Init() ' LCD
Lcd_Cmd(_LCD_CURSOR_OFF) ' LCD (off)
Lcd_Cmd(_LCD_CLEAR) ' LCD command (clear LCD)
text = "mikroElektronika" ' First message
Lcd_Out(1,1,text) ' First message, first line
text = "LCD example" ' Second message
Lcd_Out(2,1,text) ' Second message, second line
Delay_ms(500)
text = "Voltage=" ' Third message
while 1 ' Loop
adc_rd = ADC_Read(0) ' A/D conversion. RA0 input.
Lcd_Out(2,1,text) ' Result second line
tlong = adc_rd * 5000 ' Milivolt
tlong = tlong / 1023 ' 0..1023 -> 0-5000mV
ch = (tlong / 1000) mod 10 '
'
Lcd_Chr(2,9,48+ch) '
Lcd_Chr_CP(".") '
ch = (tlong / 100) mod 10 '
Lcd_Chr_CP(48+ch) '
ch = (tlong / 10) mod 10 '
Lcd_Chr_CP(48+ch) '
ch = tlong mod 10 '
Lcd_Chr_CP(48+ch) '
Lcd_Chr_CP("V") ' Show "V"
Delay_ms(1) ' 1mS delay
wend
end.
tlong = adc_rd * 5000 ' Milivolt
tlong = tlong / 1023 ' 0..1023 -> 0-5000mV
tlong = (adc_rd * 5000) >> 10
dim tempt as word
tlong = (adc_rd * 5000) >> 10
tempt = tlong
ch = (tlong / 1000) mod 10 '
'
Lcd_Chr(2,9,48+ch) '
Lcd_Chr_CP(".") '
ch = (tlong / 100) mod 10 '
Lcd_Chr_CP(48+ch) '
ch = (tlong / 10) mod 10 '
Lcd_Chr_CP(48+ch) '
ch = tlong mod 10 '
Lcd_Chr_CP(48+ch)
ch = (tempt / 1000) mod 10 '
'
Lcd_Chr(2,9,48+ch) '
Lcd_Chr_CP(".") '
ch = (tempt / 100) mod 10 '
Lcd_Chr_CP(48+ch) '
ch = (tempt / 10) mod 10 '
Lcd_Chr_CP(48+ch) '
ch = tempt mod 10 '
Lcd_Chr_CP(48+ch)
its very simple....u have selected the wrong chip for ur program. all u need to do is to change the microcontroller that u hav their in ur design to a controller with enough flash memory for the program that u are developing. say for example 16F877A,873A etc they hav 8KB and 4KB of memory respectively. and they also hav an embedded adc unlike the 16F676 that u hav opt for.....hope this helps
Sequel
This program is under 2KB and he select right uC 16F676.
Change the code a little.
Change these 2 lines:
Code:tlong = adc_rd * 5000 ' Milivolt tlong = tlong / 1023 ' 0..1023 -> 0-5000mV
to
Code:tlong = (adc_rd * 5000) >> 10
Also, declare a 16-bit variable at the beginning of the code:
Code:dim tempt as word
After the line:
Code:tlong = (adc_rd * 5000) >> 10
add:
Code:tempt = tlong
Then replace this:
Code:ch = (tlong / 1000) mod 10 ' ' Lcd_Chr(2,9,48+ch) ' Lcd_Chr_CP(".") ' ch = (tlong / 100) mod 10 ' Lcd_Chr_CP(48+ch) ' ch = (tlong / 10) mod 10 ' Lcd_Chr_CP(48+ch) ' ch = tlong mod 10 ' Lcd_Chr_CP(48+ch)
with this:
Code:ch = (tempt / 1000) mod 10 ' ' Lcd_Chr(2,9,48+ch) ' Lcd_Chr_CP(".") ' ch = (tempt / 100) mod 10 ' Lcd_Chr_CP(48+ch) ' ch = (tempt / 10) mod 10 ' Lcd_Chr_CP(48+ch) ' ch = tempt mod 10 ' Lcd_Chr_CP(48+ch)
Make the modifications I showed above and try again.
Hope this helps.
Tahmid.
Yes, it was. Avoid using large variables unless absolutely necessary. Here, your result would be less than 5000. So, instead of carrying out calculations on a 32-bit variable, calculations were done on a 16-bit variable, which was enough.
Just a tip: Also avoid using floating point calculations and divisions (and multiplication), especially by large numbers, unless absolutely necessary.
program F676_expADC
' Declarations section
dim data7, num7 as byte
dim adc_rd, tempt as word
dim tlong as longword
dim digit as byte[4]
sub procedure send7 (dim value, seven as byte)
'Changed to Common Cathode Display
PORTA = 0
select case value
case 0 data7 = 0
case 1 data7 = 1
case 2 data7 = 2
case 3 data7 = 3
case 4 data7 = 4
case 5 data7 = 5
case 6 data7 = 6
case 7 data7 = 7
case 8 data7 = 8
case 9 data7 = 9
end select
PORTC = data7
TRISA=1
select case seven
case 1
RC4_bit = 1
case 2
RC5_bit = 1
case 3
RA1_bit = 1
case 4
RA2_bit = 1
end select
end sub
sub procedure Settings
CMCON=7
ANSEL=%00000001
ADCON1=%00000000
ADCON0=%10000001
TRISC=0
end sub
sub procedure delay2ms
delay_ms(2)
end sub
main:
' Main program
Settings()
while true
adc_rd = ADC_Read(0) ' A/D conversion. RA0 input.
tlong = (adc_rd * 5000) >> 10
tempt = tlong
digit[0] = (tempt / 1000) mod 10 '
digit[1] = (tempt / 100) mod 10
digit[2] = (tempt / 10) mod 10
digit[3] = tempt mod 10
send7(digit[0],1)
delay2ms()
send7(digit[1],2)
delay2ms()
send7(digit[2],3)
delay2ms()
send7(digit[3],4)
delay2ms()
wend
end.
Please upload the Proteus DSN file.
It works fine for me:
You should call ADC_Init() function in the initialization routine after ADCON settings. You have to set ADCON1 register.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?