Thông báo

Collapse
No announcement yet.

Cần mọi người giúp đỡ về đo nhiệt giao tiếp máy với máy sử dụng AT89 + ADC

Collapse
X
 
  • Lọc
  • Giờ
  • Show
Clear All
new posts

  • Cần mọi người giúp đỡ về đo nhiệt giao tiếp máy với máy sử dụng AT89 + ADC

    Tình hình là em đang làm cái đồ án giao tiếp với máy tính dùng AT89 đọc dữ liệu từ ADC gửi lên máy tính, em làm mô phỏng ở máy tính thì chạy được, đến khi nạp vào KIT thật thì không chạy. Nạp thử code khác KIT vẫn chạy được. Mong mọi người giúp đỡ xem dùm em cái code.
    Đây là KIT của em:
    Click image for larger version

Name:	Chưa có tên.jpg
Views:	1
Size:	49.5 KB
ID:	1418670
    Code Vb 10:
    Code:
    Public Class Form1
        Dim Data As String
        Dim Flag As Integer
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    SerialPort1.Open()
            Timer1.Enabled = True
            Data = " "
            Flag = 0
        End Sub
    
        Private Sub LED1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LED1.CheckedChanged
            If LED1.Checked Then
                SerialPort1.Write("A")
                Button1.BackColor = Color.Green
            Else : SerialPort1.Write("E")
                Button1.BackColor = Color.Black
            End If
        End Sub
    
        Private Sub LED2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LED2.CheckedChanged
            If LED2.Checked Then
                SerialPort1.Write("B")
                Button2.BackColor = Color.Green
            Else : SerialPort1.Write("F")
                Button2.BackColor = Color.Black
            End If
        End Sub
    
        Private Sub LED3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LED3.CheckedChanged
            If LED3.Checked Then
                SerialPort1.Write("C")
                Button3.BackColor = Color.Green
            Else : SerialPort1.Write("G")
                Button3.BackColor = Color.Black
            End If
        End Sub
    
        Private Sub LED4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LED4.CheckedChanged
            If LED4.Checked Then
                SerialPort1.Write("D")
                Button4.BackColor = Color.Green
            Else : SerialPort1.Write("H")
                Button4.BackColor = Color.Black
            End If
        End Sub
    
        Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
            SerialPort1.Close()
            Application.Exit()
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
        End Sub
    
        Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LED5.CheckedChanged
            If LED5.Checked Then
                SerialPort1.Write("J")
                Button6.BackColor = Color.Green
            Else : SerialPort1.Write("K")
                Button6.BackColor = Color.Black
            End If
        End Sub
    
        Private Sub LED6_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LED6.CheckedChanged
            If LED6.Checked Then
                SerialPort1.Write("L")
                Button7.BackColor = Color.Green
            Else : SerialPort1.Write("Z")
                Button7.BackColor = Color.Black
            End If
        End Sub
    
        Private Sub LED7_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LED7.CheckedChanged
            If LED7.Checked Then
                SerialPort1.Write("X")
                Button8.BackColor = Color.Green
            Else : SerialPort1.Write("C")
                Button8.BackColor = Color.Black
            End If
        End Sub
    
        Private Sub LED8_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LED8.CheckedChanged
            If LED8.Checked Then
                SerialPort1.Write("N")
                Button9.BackColor = Color.Green
            Else : SerialPort1.Write("M")
                Button9.BackColor = Color.Black
            End If
        End Sub
    
        Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    
        End Sub
    
        Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            If (Flag = 1) Then
                TextBox1.Text = (Data)
                Flag = 0
            End If
        End Sub
    
        Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
    
        End Sub
    
        Private Sub SerialPort1_DataReceived(ByVal sender As System.Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
            System.Threading.Thread.Sleep(100)
            Data = SerialPort1.ReadExisting()
            Flag = 1
        End Sub
    End Class
    Code C vi điều khiển:
    Code:
    #include <Regx51.h>
    #include <stdio.h>
    #include <math.h>
    
    unsigned char dladc;
    float mv,nd;
    sbit wr = P3^2;
    sbit LED1=P2^0;
    sbit LED2=P2^1;
    sbit LED3=P2^2;
    sbit LED4=P2^3;
    sbit LED5=P2^4;
    sbit LED6=P2^5;
    sbit LED7=P2^6;
    sbit LED8=P2^7;
    char date=0;
    void delay(unsigned int adc)
    	{
    	unsigned int i;
    	for(i=0;i<=adc;i++);
    	}
    
     void goi(unsigned int num)
    	{
    	unsigned char t,c,d;
    	t=num/100;
    	c=(num%100)/10;
    	d=(num%100)%10;
    	putchar(t+48);
    	putchar(c+48);
    	putchar(d+48);
    	}
     unsigned char read_adc()
    	{
    	wr =1; delay (10);
    	wr=0;	delay(10);
    	delay(100);
    	return P1;
    	}
    void uart()
    {
    	SCON=0x52;
    	TMOD=0x21;
    	TH1=TL1=0xfd;
    	TR1=1;
    }
    void main()
    {	//uart();
    	IE=0x90;
    	RI=0;
    	//P0=0xff;
    	while(1)
    	{
    		if(date=='A') LED1 = 0;	
    		else if(date=='B') LED2=0;
    		else if(date=='C') LED3=0;
    		else if(date=='D') LED4=0;
    		else if(date=='J') LED5=0;
    		else if(date=='L') LED6=0;
    		else if(date=='X') LED7=0;
    		else if(date=='N') LED8=0;
    		else if(date=='E') LED1=1; 
    		else if(date=='F') LED2=1;
    		else if(date=='G') LED3=1; 
    		else if(date=='H') LED4=1;
    		else if(date=='K') LED5=1;
    		else if(date=='Z') LED6=1;
    		else if(date=='V') LED7=1;
    		else if(date=='M') LED8=1;
    		dladc=read_adc();
    		nd=1.96*dladc;
    		goi(nd);
    		delay(1000);
    	}
    }
    void ngat()	interrupt 4
    {
     	date=SBUF;
    	RI=0;
    }
    Mong được mọi người giúp đỡ.

Về tác giả

Collapse

libicay2993 Tìm hiểu thêm về libicay2993

Bài viết mới nhất

Collapse

Đang tải...
X