the_balistic
Member level 2
atmega8535 project
Dear Forum,
I need your suggestion and solution. I have problem with my semester project, I make data acquisition using AVR Atmega 8535 and Delphi 5. This data acquisition use for measure voltage (ADC 10 bits) and the result will be display at LCD Graphic and Delphi Chart. I use four channel ADC from Atmega and I use library CPORT 2.63 from Dejan Carmila.
This my code for avr : (I use bascom avr series 1.11.9.0)
I've already test serial communication with hyper terminal (baud rate 9600 bps) and the result is no problem with serial communication :
e(1)=838
e(2)= 70
e(3)=986
e(4)=786
But the problem is when Delphi receive data using onRxchar, the data is wrong
(I just sent the adc value no all of the data i modify the serial sub program i just send one channel adc value, i modify the sub serial program :
But The memo and label shows the wrong value.
Here is my delphi program :
I want this data (838) can be convert to integer type so can be manipulate for chart and label. Please need your help and support !
Dear Forum,
I need your suggestion and solution. I have problem with my semester project, I make data acquisition using AVR Atmega 8535 and Delphi 5. This data acquisition use for measure voltage (ADC 10 bits) and the result will be display at LCD Graphic and Delphi Chart. I use four channel ADC from Atmega and I use library CPORT 2.63 from Dejan Carmila.
This my code for avr : (I use bascom avr series 1.11.9.0)
Code:
$regfile = "m8535.dat"
$crystal = 4000000
$baud = 9600
$hwstack = 32
$swstack = 8
$framesize = 24
'===============================================================================
Config Graphlcd = 240 * 64 , Dataport = Portb , Controlport = Portc , Ce = 5 , Cd = 4 , Wr = 6 , Rd = 7 , Reset = 4 , Fs = 1 , Mode = 8
Config Adc = Single , Prescaler = Auto , Reference = Internal
Dim X As Byte , Y As Byte , I As Integer , G As Integer
Dim W As Word , A(4) As Single , B(4) As String * 5 , C(4) As Single , D(4) As Integer , E(4) As Integer , D1 As Integer , D2 As Integer , D3 As Integer , D4 As Integer
'===============================================================================
Start Adc
Cls
Waitms 100
Cursor Off Noblink
Waitms 100
Showpic 240 , 0 , Logo
Wait 2
'===============================================================================
Main:
Do
Gosub Getvalue
Gosub Displaytext
Gosub Displaybar
Gosub Sendserial
Loop
'===============================================================================
Getvalue:
For I = 1 To 4 Step 1
W = Getadc(i)
E(i) = W
C(i) = W * 0.0537109375
A(i) = W * 0.0048828125
Waitms 100
Next I
Return
'===============================================================================
Displaytext:
Locate 1 , 50 : Lcd "1="
Waitms 100
B(1) = Fusing(a(1) , "#.##")
Locate 1 , 52 : Lcd B(1)
Waitms 100
Locate 1 , 56 : Lcd "V"
Waitms 100
'===========================
Locate 3 , 50 : Lcd "2="
Waitms 100
B(2) = Fusing(a(2) , "#.##")
Locate 3 , 52 : Lcd B(2)
Waitms 100
Locate 3 , 56 : Lcd "V"
Waitms 100
'===========================
Locate 5 , 50 : Lcd "3="
Waitms 100
B(3) = Fusing(a(3) , "#.##")
Locate 5 , 52 : Lcd B(3)
Waitms 100
Locate 5 , 56 : Lcd "V"
Waitms 100
'===========================
Locate 7 , 50 : Lcd "4="
Waitms 1000
B(4) = Fusing(a(4) , "#.##")
Locate 7 , 52 : Lcd B(4)
Waitms 100
Locate 7 , 56 : Lcd "V"
Waitms 100
Return
Displaybar:
For I = 1 To 4 Step 1
D(i) = 53 - Round(c(i))
If D(i) = 0 Then
D(i) = 53
Elseif D(i) =< 9 Then
D(i) = 9
Else
D(i) = D(i)
End If
D1 = D(1)
D2 = D(2)
D3 = D(3)
D4 = D(4)
Next I
'======================================
Boxfill(24 , 9) -(39 , 53) , 0
Waitms 100
Boxfill(24 , D1) -(39 , 53) , 1
Waitms 100
'======================================
Boxfill(56 , 9) -(71 , 53) , 0
Waitms 100
Boxfill(56 , D2) -(71 , 53) , 1
Waitms 100
'======================================
Boxfill(87 , 9 ) -(102 , 53 ) , 0
Waitms 100
Boxfill(87 , D3 ) -(102 , 53 ) , 1
Waitms 100
'======================================
Boxfill(120 , 9) -(135 , 53) , 0
Waitms 100
Boxfill(120 , D4) -(135 , 53) , 1
Waitms 100
Return
Sendserial:
For I = 1 To 4 Step 1
Print E(i)
Waitms 100
Next I
Return
End
Logo:
$bgf "kordinat.bgf"
I've already test serial communication with hyper terminal (baud rate 9600 bps) and the result is no problem with serial communication :
e(1)=838
e(2)= 70
e(3)=986
e(4)=786
But the problem is when Delphi receive data using onRxchar, the data is wrong
(I just sent the adc value no all of the data i modify the serial sub program i just send one channel adc value, i modify the sub serial program :
Code:
Sendserial:
Print E(1)
Waitms 100
Return
But The memo and label shows the wrong value.
Here is my delphi program :
Code:
procedure TForm1.ComPort1RxChar(Sender: TObject; Count: Integer);
var
data : integer;
a : real;
b : string;
c : string;
begin
Comport1.Readstr(b,Count);
a:= strtofloat(b);
a:= a*0.00488;
c:= floattostr(a);
Memo1.Text := Memo1.Text + c + #13#10;
label9.caption := c;
I want this data (838) can be convert to integer type so can be manipulate for chart and label. Please need your help and support !