Hello friends,
I tried to make a SWR meter.
Now I obtained a correct result of ROS but I read on LCD only a integer part of result but not the decimal and in a wrong position (0.001 instead of 1.000)
Help me please
Antonio
program adc_SWR
dim ch as byte
adc_rd as word
adc_rd1 as word
Text as char[17]
tlong as longint
ros as word
tlong1 as longint
main:
PORTD = 0 ' clear PORTD
TRISD = 0 ' designate PORTD as output (LCD is connected to PORTD)
INTCON = 0 ' disable all interrupts
Lcd_Init(PORTD) ' Lcd_Init_
Lcd_Cmd( LCD_CURSOR_OFF) ' send command to LCD (cursor off)
Lcd_Cmd(LCD_CLEAR) ' send command to LCD (clear LCD)
'Text = "mikroElektronika" ' assign text to string a
'Lcd_Out(1,1, Text) ' print string a on LCD, 1st row, 1st column
OPTION_REG = $80
ADCON1 = $82 ' configure VDD as Vref, and analog channels
TRISA = $FF ' designate porta as input
Delay_ms(2000)
Text = "Voltage: " ' assign text to string a
Lcd_Out(2, 1, Text) ' print string a on LCD, 2nd row, 1st column
Lcd_Out(1, 16, "Vdir/Vrif")
Lcd_Out(2, 1, "R.O.S. = ")
while TRUE
' adc_rd = ADC_read(0) ' get ADC value from 1st channel
adc_rd = 200 ' valore caricato x debug
tlong = adc_rd*5000 ' trasformazione per fondo scala 5 volt
adc_rd = tlong >> 10 ' divisione per 1024 (10 bit)
ch = adc_rd div 1000 ' prepare value for diplay
Lcd_Chr(1, 3, 48+ch) ' write ASCII at 1st row, 9th column
Lcd_Chr(1, 4, ".")
ch = (adc_rd div 100) mod 10
Lcd_Chr(1, 5, 48+ch)
ch = (adc_rd div 10) mod 10
Lcd_Chr(1, 6, 48+ch)
ch = adc_rd mod 10
Lcd_Chr(1, 7, 48+ch)
delay_ms(1)
' adc_rd1 = ADC_read(1) ' get ADC value from 2nd channel
adc_rd1 = 20 ' valore caricato x debug
tlong = adc_rd1*5000 ' trasformazione per fondo scala 5 volt
adc_rd1 = tlong >> 10 ' divisione per 1024 (10 bit)
ch = adc_rd1 div 1000 ' prepare value for diplay
Lcd_Chr(1, 9, 48+ch) ' write ASCII at 2nd row, 9th column
Lcd_Chr(1, 10, ".")
ch = (adc_rd1 div 100) mod 10
Lcd_Chr(1, 11, 48+ch)
ch = (adc_rd1 div 10) mod 10
Lcd_Chr(1, 12, 48+ch)
ch = adc_rd1 mod 10
Lcd_Chr(1, 13, 48+ch)
delay_ms(1)
ros=(adc_rd+adc_rd1) / (adc_rd-adc_rd1)
'tlong1 = ros
'ros = tlong1 >> 10
ch = ros div 1000 ' prepare value for diplay
Lcd_Chr(2, 12, 48+ch) ' write ASCII at 2nd row, 9th column
Lcd_Chr(2, 13, ".")
ch = (ros div 100) mod 10
Lcd_Chr(2, 14, 48+ch)
ch = (ros div 10) mod 10
Lcd_Chr(2, 15, 48+ch)
ch = ros mod 10
Lcd_Chr(2, 16, 48+ch)
delay_ms(1)
wend
end.