Tải bản đầy đủ - 0 (trang)
I .Kết quả đạt được

I .Kết quả đạt được

Tải bản đầy đủ - 0trang

sbit den



=P1^1;



sbit quat



=P1^0;



void delay (unsigned int j)

{

unsigned int i;

for(i=0;i<=j;i++);

}

long int i;

char M[5];

unsigned char DO_ADC,x[10];

unsigned int dem;

unsigned int temp,doc;

unsigned char x1,x2,x3;

void main ()

{

unsigned char i;

// khoi tao uart 8 bit toc do 9600baud,1 bit dung

// stick=break=patity=0

SCON=0x52;

TMOD=0x20;

TH1=TL1=-3;

TR1=1;

while(1)

{

temp = 0;

32



for(i=0;i<5;i++)

{

WR_ADC=0;

delay(3);

WR_ADC=1;

delay(10);

x[i]=P2;

temp=temp+x[i];

delay(10);

}

temp = temp/5;

if(RI==0)

{

x1=SBUF; RI=0;

if(x1=='@')

{

x2=_getkey();

x3=_getkey();

}

}

putchar('$');

putchar(temp);

if(temp
if(temp>x3) quat=1; else quat =0;

//delay(500);



33



}

}

1.2 Chương trình cho VB 6

Option Explicit

Dim n As Integer

Dim kt As String

Dim x As String

Dim temp As Integer

Dim dienap As Single 'Integer

Dim x1 As Integer

Dim y1 As Integer

Dim counter1 As Integer

Dim array_x1(10000) As Integer

Dim array_y1(10000) As Integer

Dim ve As Boolean

Private Sub Command1_Click()

MSComm1.Output = "@"

MSComm1.Output = Chr(Val(Text2.Text))

MSComm1.Output = Chr(Val(Text3.Text))

MSComm1.Output = "@"

MSComm1.Output = Chr(Val(Text2.Text))

MSComm1.Output = Chr(Val(Text3.Text))

MSComm1.Output = "@"

34



MSComm1.Output = Chr(Val(Text2.Text))

MSComm1.Output = Chr(Val(Text3.Text))

MSComm1.Output = "@"

MSComm1.Output = Chr(Val(Text2.Text))

MSComm1.Output = Chr(Val(Text3.Text))

MSComm1.Output = "@"

MSComm1.Output = Chr(Val(Text2.Text))

MSComm1.Output = Chr(Val(Text3.Text))

MSComm1.Output = "@"

MSComm1.Output = Chr(Val(Text2.Text))

MSComm1.Output = Chr(Val(Text3.Text))

MSComm1.Output = "@"

MSComm1.Output = Chr(Val(Text2.Text))

MSComm1.Output = Chr(Val(Text3.Text))

MSComm1.Output = "@"

MSComm1.Output = Chr(Val(Text2.Text))

MSComm1.Output = Chr(Val(Text3.Text))

MSComm1.Output = "@"

MSComm1.Output = Chr(Val(Text2.Text))

MSComm1.Output = Chr(Val(Text3.Text))

MSComm1.Output = "@"

MSComm1.Output = Chr(Val(Text2.Text))

MSComm1.Output = Chr(Val(Text3.Text))

MSComm1.Output = "@"

MSComm1.Output = Chr(Val(Text2.Text))

MSComm1.Output = Chr(Val(Text3.Text))

35



MSComm1.Output = "@"

MSComm1.Output = Chr(Val(Text2.Text))

MSComm1.Output = Chr(Val(Text3.Text))

MSComm1.Output = "@"

MSComm1.Output = Chr(Val(Text2.Text))

MSComm1.Output = Chr(Val(Text3.Text))

MSComm1.Output = "@"

MSComm1.Output = Chr(Val(Text2.Text))

MSComm1.Output = Chr(Val(Text3.Text))

MSComm1.Output = "@"

MSComm1.Output = Chr(Val(Text2.Text))

MSComm1.Output = Chr(Val(Text3.Text))

MSComm1.Output = "@"

MSComm1.Output = Chr(Val(Text2.Text))

MSComm1.Output = Chr(Val(Text3.Text))

MSComm1.Output = "@"

MSComm1.Output = Chr(Val(Text2.Text))

MSComm1.Output = Chr(Val(Text3.Text))

MSComm1.Output = "@"

MSComm1.Output = Chr(Val(Text2.Text))

MSComm1.Output = Chr(Val(Text3.Text))

MSComm1.Output = "@"

MSComm1.Output = Chr(Val(Text2.Text))

MSComm1.Output = Chr(Val(Text3.Text))

MSComm1.Output = "@"

MSComm1.Output = Chr(Val(Text2.Text))

36



MSComm1.Output = Chr(Val(Text3.Text))

MSComm1.Output = "@"

MSComm1.Output = Chr(Val(Text2.Text))

MSComm1.Output = Chr(Val(Text3.Text))

MSComm1.Output = "@"

MSComm1.Output = Chr(Val(Text2.Text))

MSComm1.Output = Chr(Val(Text3.Text))

MSComm1.Output = "@"

MSComm1.Output = Chr(Val(Text2.Text))

MSComm1.Output = Chr(Val(Text3.Text))

MSComm1.Output = "@"

MSComm1.Output = Chr(Val(Text2.Text))

MSComm1.Output = Chr(Val(Text3.Text))

MSComm1.Output = "@"

MSComm1.Output = Chr(Val(Text2.Text))

MSComm1.Output = Chr(Val(Text3.Text))

MSComm1.Output = "@"

MSComm1.Output = Chr(Val(Text2.Text))

MSComm1.Output = Chr(Val(Text3.Text))

MSComm1.Output = "@"

MSComm1.Output = Chr(Val(Text2.Text))

MSComm1.Output = Chr(Val(Text3.Text))

MSComm1.Output = "@"

MSComm1.Output = Chr(Val(Text2.Text))

MSComm1.Output = Chr(Val(Text3.Text))

MSComm1.Output = "@"

37



MSComm1.Output = Chr(Val(Text2.Text))

MSComm1.Output = Chr(Val(Text3.Text))

MSComm1.Output = "@"

MSComm1.Output = Chr(Val(Text2.Text))

MSComm1.Output = Chr(Val(Text3.Text))

MSComm1.Output = "@"

MSComm1.Output = Chr(Val(Text2.Text))

MSComm1.Output = Chr(Val(Text3.Text))

MSComm1.Output = "@"

MSComm1.Output = Chr(Val(Text2.Text))

MSComm1.Output = Chr(Val(Text3.Text))

MSComm1.Output = "@"

MSComm1.Output = Chr(Val(Text2.Text))

MSComm1.Output = Chr(Val(Text3.Text))

MSComm1.Output = "@"

MSComm1.Output = Chr(Val(Text2.Text))

MSComm1.Output = Chr(Val(Text3.Text))

MSComm1.Output = "@"

MSComm1.Output = Chr(Val(Text2.Text))

MSComm1.Output = Chr(Val(Text3.Text))

MSComm1.Output = "@"

MSComm1.Output = Chr(Val(Text2.Text))

MSComm1.Output = Chr(Val(Text3.Text))

End Sub



38



Private Sub Command2_Click()

End

End Sub

Private Sub Command3_Click()

If MSComm1.PortOpen = False Then ' mo cong

With MSComm1

.Settings = "9600,N,8,1" ' thiet dat cau hinh cong

.CommPort = Text4.Text 'su dung cong COM1

.RThreshold = 1 ' so byte trong bo dem nhan lam phat sinh su kien OnComm

.SThreshold = 0 'so byte trong bo dem truyen, =0 =>ko tao su kien OnComm

.InputMode = 0 'comInputModeText 0

.InputLen = 2 'Doc toan bo du lieu trong bo dem nhan

.Handshaking = comNone 'ko dung giao thuc bat tay

.InBufferSize = 1024



'dat va xac dinh kich thuc bo dem nhan la 1024 byte



.OutBufferSize = 1024 'dat va xac dinh kich thuc bo dem truyen la 1024 byte

End With

MSComm1.PortOpen = True

End If

End Sub

Private Sub Form_Load()

'--------------------------- COM1



39



'----------------------------COM

x1 = 2170



'toa do ban dau cho x1



counter1 = 0

'---------------------------End Sub



Private Sub MSComm1_OnComm()

Dim thangdo As String

If MSComm1.CommEvent = 2 Then 'comEvReceive = 2(neu co du lieu dau

vao)

kt = MSComm1.Input ' doc du lieu dau vao tu cong Com

temp = Asc(Right(kt, 1)) 'tra ve 1 con so, so nay la ma ASCII cua ki tu string

'neu la 1 chuoi nhieu ki tu thi lay ki tu dau tien

Text1.Text = Str(temp) ' doi gia tri doc duoc tu cong noi tiep sang chuoi va ghi

vao text1

dienap = temp 'o bo ADC 250 tuong ung voi 2.5V nen chia 100

'Text2.Text = dienap 'temp - 42 (hien thi nhiet do len text2)



40



End If

End Sub

Private Sub start_Click()

ve = True

End Sub

Private Sub stop_Click()

ve = False

End Sub

Private Sub Timer1_Timer() 'Timer=100ms dung de ve do thi

Label6.Caption = "Thoi gian: " & Format(Now, "ddd dd-mmm-yyyy hh:nn:ss")

'Hien thi thoi gian hien tai dang: day date month year hour minutes seconds

If ve = True Then



'Neu bien ve= true thi ve do thi



vedothi (temp)

End If



End Sub

Public Sub vedothi(t As Single)

counter1 = counter1 + 1 'Bo dem so dien lay dien ap

x1 = x1 + 30 ' 1s 36

y1 = Int(7800 - t * (6000 / 100)) '50 -->100%

41



array_x1(counter1) = x1 'luu toa do x

array_y1(counter1) = y1 'luu toa do y

Circle (x1, y1), 20, vbRed ' ve duong tron mau do

Line (x1, y1 + 25)-(x1, 7800), &H8000& ' ve duong thang

If counter1 >= 360 Then ' xoa khi ve het man hinh

xoa_manhinh

End If

End Sub

Public Sub xoa_manhinh() ' gan nhung diem da ve bang mau nen

Dim i As Integer

Dim k As Integer

k = counter1



'



For i = 1 To k

x1 = array_x1(i)

y1 = array_y1(i)

Circle (x1, y1), 20, &HFFFFFF



'xoa duong tron



Line (x1, y1 + 25)-(x1, 7800), &HFFFFFF



'xoa duong thang



Next

counter1 = 0



'xoa bo dem



x1 = 2170



'reset toa do ban dau bien x1



End Sub



42



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

I .Kết quả đạt được

Tải bản đầy đủ ngay(0 tr)

×