VB6 讀取8051 LED燈的訊號 (C語言) |
尚未結案
|
drkmaves
一般會員 發表:1 回覆:1 積分:0 註冊:2014-04-21 發送簡訊給我 |
|
pedro
尊榮會員 發表:152 回覆:1187 積分:892 註冊:2002-06-12 發送簡訊給我 |
|
drkmaves
一般會員 發表:1 回覆:1 積分:0 註冊:2014-04-21 發送簡訊給我 |
不好意思
我是新手 也沒有想要網友幫忙我寫作業 只是想討論問題 以下是 從 VB 控制 8051 LED燈亮與暗 我想改成 8051 傳送自己的LED燈亮與暗(使用指撥開關控制高低電位) 然後再VB6上面顯示LED與8051同步 #include void alloff(void); void load1(void); void load2(void); void load3(void); void load4(void); void send(unsigned char k) ; main() { TMOD=0x20; TH1=230; TL1=230; TR1=1; SCON=0x70; while(1) { RI=0; while(RI==0); if(SBUF=='0') alloff(); else if(SBUF=='1') load1(); else if(SBUF=='2') load2(); else if(SBUF=='3') load3(); else if(SBUF=='4') load4(); } } void alloff(void) { P1=0xff; send('2'); } void load1(void) { P1_0 = !P1_0; if(P1_0==0) send('1'); else send('0'); } void load2(void) { P1_1 = !P1_1; if(P1_1==0) send('1'); else send('0'); } void load3(void) { P1_2 = !P1_2; if(P1_2==0) send('1'); else send('0'); } void load4(void) { P1_3 = !P1_3; if(P1_3==0) send('1'); else send('0'); } void send(unsigned char k) { TI=0; SBUF=k; while(TI==0); } Private Sub Command1_Click() tex1.Text = "連線中" MSComm1.Output = "1" delayms 100 buf = MSComm1.Input If buf = "0" Then LOAD1.FillColor = RGB(0, 255, 0) ElseIf buf = "1" Then LOAD1.FillColor = RGB(255, 0, 0) Else tex1.Text = "連線失敗" End If End Sub Private Sub Command2_Click() tex1.Text = "連線中" MSComm1.Output = "2" delayms 100 buf = MSComm1.Input If buf = "0" Then LOAD2.FillColor = RGB(0, 255, 0) ElseIf buf = "1" Then LOAD2.FillColor = RGB(255, 0, 0) Else tex1.Text = "連線失敗" End If End Sub Private Sub Command3_Click() tex1.Text = "連線中" MSComm1.Output = "3" delayms 100 buf = MSComm1.Input If buf = "0" Then LOAD3.FillColor = RGB(0, 255, 0) ElseIf buf = "1" Then LOAD3.FillColor = RGB(255, 0, 0) Else tex1.Text = "連線失敗" End If End Sub Private Sub Command4_Click() tex1.Text = "連線中" MSComm1.Output = "4" delayms 100 buf = MSComm1.Input If buf = "0" Then LOAD4.FillColor = RGB(0, 255, 0) ElseIf buf = "1" Then LOAD4.FillColor = RGB(255, 0, 0) Else tex1.Text = "連線失敗" End If End Sub Private Sub Command5_Click() tex1.Text = "連線中" MSComm1.Output = "0" delayms 100 buf = MSComm1.Input If buf = "2" Then LOAD1.FillColor = RGB(0, 255, 0) LOAD2.FillColor = RGB(0, 255, 0) LOAD3.FillColor = RGB(0, 255, 0) LOAD4.FillColor = RGB(0, 255, 0) Else tex1.Text = "連線失敗" End If End Sub Private Sub Command6_Click() On Error Resume Next msg = "您確定要結束本程式嗎 ?" code = 65 Title = "關閉程式" return_value = MsgBox(msg, code, Title) If return_value = 1 Then Command5_Click MSComm1.PortOpen = False End End If End Sub Private Sub Form_Load() On Error Resume Next LOAD1.FillColor = RGB(0, 255, 0) LOAD2.FillColor = RGB(0, 255, 0) LOAD3.FillColor = RGB(0, 255, 0) LOAD4.FillColor = RGB(0, 255, 0) MSComm1.PortOpen = False MSComm1.CommPort = 1 MSComm1.PortOpen = True If MSComm1.PortOpen = True Then MSComm1.PortOpen = False MSComm1.CommPort = 1 MSComm1.Settings = "1200,n,8,1" MSComm1.PortOpen = True tex1.Text = "已自動選用COM1" Else MSComm1.PortOpen = False MSComm1.CommPort = 2 MSComm1.PortOpen = True If MSComm1.PortOpen = True Then MSComm1.PortOpen = False MSComm1.CommPort = 2 MSComm1.Settings = "1200,n,8,1" MSComm1.PortOpen = True tex1.Text = "已自動選用COM2" Else MSComm1.PortOpen = False tex1.Text = "通訊埠無法給您用" End If End If End Sub ===================引 用 pedro 文 章=================== 嗨! 看不出你在做遇到什麼問題? 是要網友幫你寫作業? 也許你可以先google一下... ===================引 用 drkmaves 文 章=================== 當8051 用開關切換 LED燈 亮跟暗 8051>RS232>VB6 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |