?? 單片機c51編程幾個有用的模塊--祥子的天空.htm
字號:
接收4個字節長的數據包<BR>}<BR>}<BR><BR>// 在中斷外部響應時鐘中斷事件<BR>void
OnTimerEvent() <BR>{<BR> // do
nothing<BR>}<BR><BR>// 控制外部燈<BR>static void
TriggerLamp(BIT bEnable) <BR>{<BR> P10 =
~bEnable; // 需要反相控制<BR>}<BR><BR>//
鍵掃描回調函數<BR>BYTE KBScan() <BR>{<BR> BIT b;<BR> P11 =
1; // 讀之前拉高引腳電平<BR> b =
P11; // 讀入引腳狀態<BR> return
~b; // 數據反相做掃描碼<BR>}<BR><BR>//
計算校驗和<BR>static BYTE CalcCheckSum(BYTE* pbyBuf, BYTE
byLen)<BR>{<BR> BYTE by, bySum = 0;<BR> for(by = 0; by
< byLen; by++)<BR> bySum +=
pbyBuf[by];<BR> return 0 – bySum;<BR>}<BR><BR>//
接收到鍵盤消息回調函數<BR>void onKeyPressed(BYTE byValue, BYTE
byState)<BR>{<BR> BYTE by[4];<BR> if(byState ==
0)<BR> {<BR> switch(byValue)<BR> {<BR> case
0x01:<BR> gbitLampState = ~g bitLampState; //
燈狀態取反<BR> TriggerLamp(gbitLampState); //
執行控制<BR> by[0] = 0xff; //
構造數據包<BR> by[1] = 0x12;<BR> by[2] =
(BYTE)gbitLampState;<BR> by[3] = CalcCheckSum(by,
3); // 求校驗和<BR> SendPackage(by, 4); //
發送數據包<BR> break;<BR> //
處理其它掃描碼<BR> default:<BR> break;<BR> }<BR>}<BR><BR>//
接收到數據包回調函數<BR>void OnRecePackage(BYTE* pbyBuf, BYTE
byBufLen)<BR>{<BR> BYTE by[4];<BR> by[0] =
0xff;<BR> by[1] = 0x11;<BR> if(byBufLen != 4 ||
pbyBuf[3] != CalcCheckSum(pbyBuf,
3))<BR> {<BR> by[2] = 0;<BR> by[3] =
CalcCheckSum(by, 3);<BR> SendPackage(by, 4);
//
處理長度或校驗和不正確<BR> }<BR><BR> switch(pbyBuf[1])<BR> {<BR> case
0x10:<BR> gbitLampState =
(BIT)pbyBuf[2];<BR> TriggerLamp(gbitLampState);<BR> by[2]
= 1;<BR> by[3] = CalcCheckSum(by,
3);<BR> SendPackage(by, 4); //
發送成功執行通知<BR> break;<BR><BR> default: //
不知道的命令<BR> by[2] = 0;<BR> by[3] = CalcCheckSum(by,
3);<BR> SendPackage(by, 4); //
發送沒有成功執行通知<BR> break;<BR></FONT></SPAN></SPAN></DIV></SPAN></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD height=3> </TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD class=seyle5 height=13>
<DIV align=right><SPAN class=textbox-urls><A
href="http://www.mcublog.com/blog/user1/7352/archives/2007/26141.html#">閱讀全文<SPAN
id=ob_logreaded></SPAN></A> | <A
href="http://www.mcublog.com/blog/user1/7352/archives/2007/26141.html#cmt">回復(1)</A>
<SPAN id=ob_logm26141></SPAN>| <A
href="http://www.mcublog.com/blog/showtb.asp?id=26141"
target=_blank>引用通告<SPAN id=ob_tbnum></SPAN></A> | <A
href="http://www.mcublog.com/blog/user_post.asp?logid=26141"
target=_blank>編輯</A></SPAN></DIV></TD></TR></TBODY></TABLE>
<TABLE height=14 cellSpacing=0 cellPadding=0 width="100%"
align=center border=0>
<TBODY>
<TR>
<TD> </TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
<DIV id=blogaddon>
<LI>標簽:<SPAN><A
href="http://www.mcublog.com/blog/user1/7352/cmd.html?uid=7352&do=tag_blogs&id=579">C51編程</A></SPAN> <SPAN><A
href="http://www.mcublog.com/blog/user1/7352/cmd.html?uid=7352&do=tag_blogs&id=4473">常用模塊</A></SPAN> </LI></DIV>
<DIV id=morelog>
<UL>
<LI>上一篇:<A
href="http://www.mcublog.com/blog/user1/7352/archives/2007/26140.html">uC/OS開發方法(續)</A>
<LI>下一篇:<A
href="http://www.mcublog.com/blog/user1/7352/archives/2007/26142.html">PWM控制LED燈漸亮漸滅源程序</A>
</LI></UL></DIV>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD>
<TABLE class=seyle4 cellSpacing=0 cellPadding=0 width="100%"
border=0>
<TBODY>
<TR>
<TD> </TD></TR>
<TR>
<TD class=content9
vAlign=center><STRONG>Re:單片機C51編程幾個有用的模塊<A
name=10764></A></STRONG></TD></TR>
<TR>
<TD>
<DIV align=right><SPAN class=textbox-label>[ <SPAN
id=t_10764>2007-12-8 20:07:46</SPAN> | By: <SPAN
class=style3><SPAN id=n_10764>sky411615400</SPAN></SPAN>
]</SPAN></DIV></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD height=3> </TD></TR></TBODY></TABLE>
<TABLE style="TABLE-LAYOUT: fixed" cellSpacing=0 cellPadding=0
width="100%" align=center border=0>
<TBODY>
<TR>
<TD><SPAN class=oblog_text><A
href="http://www.mcublog.com/blog/go.asp?url=http://nike.mcublog.com"
target=_blank><IMG class=ob_face height=48
alt=sky411615400
src="單片機C51編程幾個有用的模塊--祥子的天空.files/ico_default.gif"
width=48 align=absMiddle></A><SPAN
id=c_10764>非常好的東西,謝謝,希望有時候咄咄指教</SPAN>
</SPAN></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD height=3> </TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD class=seyle5 height=13>
<DIV align=right><SPAN class=textbox-urls><A
href="http://www.mcublog.com/blog/go.asp?url=http://nike.mcublog.com"
target=_blank>個人主頁</A> | <A
href="javascript:reply_quote('10764')">引用</A> | <A
href="http://www.mcublog.com/blog/user1/7352/archives/2007/26141.html#top">返回</A>
| <A
href="http://www.mcublog.com/blog/user_comments.asp?action=del&id=10764"
target=_blank>刪除</A> | <A
href="http://www.mcublog.com/blog/user_comments.asp?action=modify&re=true&id=10764"
target=_blank>回復</A></SPAN></DIV></TD></TR></TBODY></TABLE>
<TABLE height=14 cellSpacing=0 cellPadding=0 width="100%"
align=center border=0>
<TBODY>
<TR>
<TD> </TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>
<DIV id=form_comment>
<DIV id=gg_usercomment></DIV><A name=cmt></A>
<DIV class=title>發表評論:</DIV>
<FORM id=commentform name=commentform
onsubmit="return Verifycomment()"
action=/blog/savecomment.asp?logid=26141 method=post>
<DIV class=d1><LABEL>昵稱:<INPUT id=UserName maxLength=20
name=UserName></LABEL></DIV>
<DIV class=d2><LABEL>密碼:<INPUT id=Password type=password
maxLength=20 name=Password> </LABEL></DIV>
<DIV class=d3><LABEL>主頁:<INPUT id=homepage maxLength=50 size=42
value=http:// name=homepage></LABEL></DIV>
<DIV class=d4><LABEL>標題:<INPUT id=commenttopic maxLength=50 size=42
value=Re:單片機C51編程幾個有用的模塊 name=commenttopic></LABEL></DIV>
<DIV class=d5><INPUT id=edit type=hidden name=edit>
<DIV id=oblog_edit>數據載入中...</DIV></DIV>
<DIV class=d6><SPAN id=ob_code></SPAN><INPUT onclick='oblog_edittext.createTextRange().execCommand("Copy");' type=submit value= 提 交 ></DIV></FORM></DIV></TD></TR></TBODY></TABLE></DIV></TD>
<TD width=112> </TD></TR></TBODY></TABLE>
<TABLE class=content6 cellSpacing=0 cellPadding=0 width=996 border=0>
<TBODY>
<TR>
<TD width=182 height=37> </TD>
<TD width=637> </TD>
<TD width=177> </TD></TR>
<TR>
<TD height=84> </TD>
<TD align=middle></TD>
<TD> </TD></TR>
<TR>
<TD> </TD>
<TD> </TD>
<TD> </TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><SPAN
id=gg_userbot></SPAN>
<DIV id=powered><A href="http://www.mcublog.com/" target=_blank><IMG
alt="Powered by Mcublog." src="單片機C51編程幾個有用的模塊--祥子的天空.files/oblog_powered.gif"
border=0></A>
<SCRIPT language=javascript
src="單片機C51編程幾個有用的模塊--祥子的天空.files/click.htm"></SCRIPT>
</DIV>
<SCRIPT src="單片機C51編程幾個有用的模塊--祥子的天空.files/200712.htm"></SCRIPT>
<SCRIPT src="單片機C51編程幾個有用的模塊--祥子的天空.files/count.htm"></SCRIPT>
<SCRIPT src="單片機C51編程幾個有用的模塊--祥子的天空.files/commentedit.htm"></SCRIPT>
<SCRIPT src="F:\ucos\新資料\單片機C51編程幾個有用的模塊--祥子的天空.files\count(1).htm"></SCRIPT>
<SCRIPT src="單片機C51編程幾個有用的模塊--祥子的天空.files/login.htm"></SCRIPT>
<SCRIPT src="單片機C51編程幾個有用的模塊--祥子的天空.files/ShowXml.htm"></SCRIPT>
<SCRIPT src="F:\ucos\新資料\單片機C51編程幾個有用的模塊--祥子的天空.files\count(2).htm"></SCRIPT>
</BODY></HTML>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -