单片机 C语言 教程

  • L8_698409
    了解作者
  • 130.4KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-05-21 07:49
    上传日期
单片机 编程学习指南(很适用于初学者) 含单片机各种应用的源程序及详细讲解
编程学习指南.rar
  • 单片机编程实例教程.pdf
    170.9KB
内容介绍
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta charset="utf-8"> <meta name="generator" content="pdf2htmlEX"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <link rel="stylesheet" href="https://static.pudn.com/base/css/base.min.css"> <link rel="stylesheet" href="https://static.pudn.com/base/css/fancy.min.css"> <link rel="stylesheet" href="https://static.pudn.com/prod/directory_preview_static/62882a1e16e0ca7141ef9166/raw.css"> <script src="https://static.pudn.com/base/js/compatibility.min.js"></script> <script src="https://static.pudn.com/base/js/pdf2htmlEX.min.js"></script> <script> try{ pdf2htmlEX.defaultViewer = new pdf2htmlEX.Viewer({}); }catch(e){} </script> <title></title> </head> <body> <div id="sidebar" style="display: none"> <div id="outline"> </div> </div> <div id="pf1" class="pf w0 h0" data-page-no="1"><div class="pc pc1 w0 h0"><img class="bi x0 y0 w1 h1" alt="" src="https://static.pudn.com/prod/directory_preview_static/62882a1e16e0ca7141ef9166/bg1.jpg"><div class="t m0 x1 h2 y1 ff1 fs0 fc0 sc0 ls0 ws0">&#21333;&#29255;&#26426;&#23398;&#20064;&#25351;&#21335;<span class="ff2 sc1 ls1"> <span class="ff1 fs1 ls2">&#36164;&#26009;&#25552;&#20379;&#65306;&#19978;&#28023;&#40784;&#27982;&#30005;&#23376;&#26377;&#38480;&#20844;&#21496;</span><span class="ls2"> </span></span></div><div class="t m0 x2 h2 y2 ff2 fs0 fc0 sc1 ls2 ws0">.1. </div><div class="t m0 x3 h3 y3 ff3 fs2 fc0 sc0 ls2 ws0"> </div><div class="t m0 x3 h3 y4 ff3 fs2 fc0 sc0 ls2 ws0"> </div><div class="t m0 x1 h4 y5 ff4 fs3 fc0 sc0 ls2 ws0">&#31532;<span class="ff3">1</span>&#31456;<span class="ff3 ls0 ws1"> PIC16F877<span class="_ _0"> </span></span><span class="ls0">&#30340;&#22806;&#22260;&#21151;&#33021;&#27169;&#22359;</span><span class="ff3"> </span></div><div class="t m0 x3 h3 y6 ff3 fs2 fc0 sc0 ls2 ws0"> </div><div class="t m0 x3 h3 y7 ff3 fs2 fc0 sc0 ls2 ws0"> </div><div class="t m0 x1 h5 y8 ff3 fs0 fc0 sc0 ls0 ws0">1.1.2 <span class="ff4">&#31616;&#21333;&#24212;&#29992;&#23454;&#20363;</span><span class="ls2"> </span></div><div class="t m0 x1 h6 y9 ff5 fs4 fc0 sc1 ls2 ws0"> <span class="_ _1"> </span><span class="ff6">&#35813;&#20363;&#29992;&#20110;&#20196;&#19982;<span class="_ _2"> </span><span class="ff7 ls3">POR<span class="_ _3"></span>TD<span class="_"> </span><span class="ff6 ls2">&#21475;&#30456;&#36830;&#30340;<span class="_ _2"> </span><span class="ff7">8<span class="_"> </span></span>&#20010;&#21457;&#20809;&#20108;&#26497;&#31649;&#21069;<span class="_ _2"> </span><span class="ff7">4<span class="_"> </span></span>&#20010;&#28857;&#20142;&#65292;<span class="_ _3"></span>&#21518;<span class="_ _2"> </span><span class="ff7">4<span class="_"> </span></span>&#20010;&#29060;&#28781;&#12290;<span class="_ _4"></span>&#22312;&#35843;&#35797;&#31243;&#24207;</span></span></span></div><div class="t m0 x1 h7 ya ff6 fs4 fc0 sc1 ls2 ws0">&#21069;&#65292;&#24212;&#20351;&#19982;<span class="_ _2"> </span><span class="ff7 ls3">POR<span class="_ _3"></span>TD<span class="_"> </span><span class="ff6 ls2">&#21475;&#30456;&#36830;&#30340;<span class="_ _2"> </span><span class="ff7">8<span class="_"> </span></span>&#20301;&#25300;&#30721;&#24320;&#20851;&#25300;&#21521;&#30456;&#24212;&#30340;&#20301;&#32622;&#12290;<span class="ff7"> </span></span></span></div><div class="t m0 x1 h8 yb ff6 fs1 fc0 sc0 ls2 ws0">&#20363;<span class="_ _5"> </span><span class="ff2 sc1 ls4 ws2">1.1 POR<span class="_ _6"></span>TD<span class="_ _5"> </span><span class="ff6 sc0 ls5 ws0">&#36755;&#20986;</span><span class="ls2 ws0"> </span></span></div><div class="t m0 x1 h7 yc ff7 fs4 fc0 sc1 ls6 ws3"> #include <span class="_ _7"></span>&lt;pic.h&gt; </div><div class="t m0 x1 h7 yd ff7 fs4 fc0 sc1 ls7 ws0">main() </div><div class="t m0 x1 h7 ye ff7 fs4 fc0 sc1 ls2 ws0">{ </div><div class="t m0 x1 h7 yf ff7 fs4 fc0 sc1 ls8 ws4"> TRISD=0X00<span class="ff6 ls2 ws0">&#65307;<span class="ff7 ls9"> <span class="_ _8"></span> /<span class="_ _9"></span>*<span class="_ _9"></span>T<span class="_ _9"></span>R<span class="_ _9"></span>I<span class="_ _9"></span>S<span class="_ _9"></span>D<span class="_ _a"></span><span class="ff6 ls2">&#23492;&#23384;&#22120;&#34987;&#36171;&#20540;&#65292;<span class="ff7 ls3">POR<span class="_ _3"></span>TD<span class="_"> </span><span class="ff6 ls2">&#27599;&#19968;&#20301;&#37117;&#20026;&#36755;&#20986;</span><span class="lsa">*/ </span></span></span></span></span></div><div class="t m0 x4 h7 y10 ff7 fs4 fc0 sc1 lsb ws0">while(1)<span class="ff6 ls2">&#65307;</span><span class="ls9"> <span class="_ _b"></span> /<span class="_ _9"></span>*<span class="_ _9"></span><span class="ff6 ls2">&#24490;&#29615;&#25191;&#34892;&#28857;&#20142;&#21457;&#20809;&#20108;&#26497;&#31649;&#30340;&#35821;&#21477;<span class="ff7 lsa">*/ </span></span></span></div><div class="t m0 x1 h7 y11 ff7 fs4 fc0 sc1 ls2 ws5"> { </div><div class="t m0 x1 h7 y12 ff7 fs4 fc0 sc1 lsc ws6"> POR<span class="_ _3"></span>TD=0XF0<span class="ff6 ls2 ws0">&#65307;</span><span class="lsd ws7"> <span class="_ _c"> </span>/*<span class="ff6 ls2 ws0">&#21521;<span class="_ _2"> </span><span class="ff7 ls3">POR<span class="_ _3"></span>TD<span class="_"> </span><span class="ff6 ls2">&#36865;&#25968;&#25454;&#65292;&#28857;&#20142;<span class="_ _2"> </span></span><span class="lse">LED<span class="ff6 ls2">&#65288;&#30001;&#23454;&#39564;&#27169;&#26495;</span><span class="lsa">*/ </span></span></span></span></span></div><div class="t m0 x5 h7 y13 ff7 fs4 fc0 sc1 lsd ws0">/*<span class="ff6 ls2">&#30340;&#35774;&#35745;&#20915;&#23450;&#30456;&#24212;&#20301;&#32622;&#20302;&#26102;<span class="_ _2"> </span></span><span class="lse">LED<span class="_"> </span><span class="ff6 ls2">&#28857;&#20142;&#65289;<span class="_ _d"></span>&#12290;<span class="ff7 lsa">*/ </span></span></span></div><div class="t m0 x4 h7 y14 ff7 fs4 fc0 sc1 ls2 ws0">} </div><div class="t m0 x1 h7 y15 ff7 fs4 fc0 sc1 ls2 ws0">} </div><div class="t m0 x1 h7 y16 ff7 fs4 fc0 sc1 lsf ws0"> </div><div class="t m0 x1 h5 y17 ff3 fs0 fc0 sc0 ls0 ws0">1.2.1 MSSP<span class="_ _e"> </span><span class="ff4">&#27169;&#22359;<span class="_ _e"> </span></span>SPI<span class="_ _e"> </span><span class="ff4">&#26041;&#24335;&#21151;&#33021;&#31616;&#20171;</span><span class="ls2"> </span></div><div class="t m0 x1 h7 y18 ff7 fs4 fc0 sc1 ls2 ws0"> <span class="_ _f"> </span><span class="ff6">&#19979;&#38754;&#26159;&#19968;&#27573;&#31616;&#21333;&#30340;<span class="_ _2"> </span></span><span class="ls10">SPI<span class="_"> </span></span><span class="ff6">&#21021;&#22987;&#21270;&#20363;&#31243;&#65292;&#29992;&#20110;&#21033;&#29992;<span class="_ _2"> </span></span><span class="ls10">SPI<span class="_"> </span></span><span class="ff6">&#24037;&#20316;&#26041;&#24335;&#36755;&#20986;&#25968;&#25454;&#30340;&#22330;&#21512;&#12290;</span> </div><div class="t m0 x1 h8 y19 ff6 fs1 fc0 sc0 ls2 ws0">&#20363;<span class="_ _5"> </span><span class="ff2 sc1 ls11 ws8">1.2 SPI<span class="_ _5"> </span></span><span class="ls5">&#21021;&#22987;&#21270;&#31243;&#24207;</span><span class="ff2 sc1"> </span></div><div class="t m0 x1 h7 y1a ff7 fs4 fc0 sc1 ls12 ws0">/*spi<span class="_"> </span><span class="ff6 ls2">&#21021;&#22987;&#21270;&#23376;&#31243;&#24207;</span><span class="lsa">*/ </span></div><div class="t m0 x1 h7 y1b ff7 fs4 fc0 sc1 ls13 ws9">void <span class="_ _10"> </span>SPIINIT() </div><div class="t m0 x1 h7 y1c ff7 fs4 fc0 sc1 ls2 ws0">{ </div><div class="t m0 x1 h7 y1d ff7 fs4 fc0 sc1 ls14 wsa"> PIR1=0<span class="ff6 ls2 ws0">&#65307;<span class="ff7 ls9"> <span class="_ _4"></span> /<span class="_ _9"></span>*<span class="_ _9"></span><span class="ff6 ls2">&#28165;&#38500;<span class="_ _5"> </span><span class="ff7 ls10">SPI<span class="_"> </span></span>&#20013;&#26029;&#26631;&#24535;<span class="ff7 lsa wsb">*/ <span class="_ _1"> </span> </span></span></span></span></div><div class="t m0 x1 h7 y1e ff7 fs4 fc0 sc1 ls15 wsc"> SSPCON=0x30<span class="ff6 ls2 ws0">&#65307;</span><span class="ls7 wsd"> <span class="_ _11"></span> /* <span class="_ _9"></span>SSPEN=1<span class="ff6 ls2 ws0">&#65307;<span class="ff7 ls16">CKP=0 <span class="_"> </span></span>&#65292;</span><span class="ls17 wse"> FOSC/4 <span class="_ _12"></span>*/ </span></span></div><div class="t m0 x1 h7 y1f ff7 fs4 fc0 sc1 ls2 ws5"> SSPST<span class="_ _3"></span>A<span class="_ _13"></span>T=0xC0<span class="ff6 ws0">&#65307;<span class="ff7"> </span></span></div><div class="t m0 x1 h7 y20 ff7 fs4 fc0 sc1 ls18 wsf"> TRISC=0x00<span class="ff6 ls2 ws0">&#65307;<span class="ff7 ls9"> <span class="_ _b"></span> /<span class="_ _9"></span>*<span class="_ _9"></span>S<span class="_ _9"></span>D<span class="_ _9"></span>O<span class="_ _a"></span><span class="ff6 ls2">&#24341;&#33050;&#20026;&#36755;&#20986;&#65292;<span class="ff7 ls19">SCK<span class="_"> </span></span>&#24341;&#33050;&#20026;&#36755;&#20986;<span class="ff7 lsa">*/ </span></span></span></span></div><div class="t m0 x1 h7 y21 ff7 fs4 fc0 sc1 ls2 ws0">}</div><div class="t m0 x6 h9 y22 ff7 fs1 fc0 sc1 ls2 ws0"> </div><div class="t m0 x1 h5 y23 ff3 fs0 fc0 sc0 ls0 ws0">1.2.3 <span class="ff4">&#31243;&#24207;&#28165;&#21333;</span><span class="ls2"> </span></div><div class="t m0 x4 h7 y24 ff6 fs4 fc0 sc1 ls2 ws0">&#19979;&#38754;&#32473;&#20986;&#24050;&#32463;&#22312;&#23454;&#39564;&#26495;&#19978;&#35843;&#35797;&#36890;&#36807;&#30340;&#19968;&#20010;&#31243;&#24207;&#65292;&#21487;&#20316;&#20026;&#29992;&#25143;&#32534;&#21046;&#20854;&#23427;&#31243;&#24207;&#30340;&#21442;&#32771;&#12290;<span class="ff7"> </span></div><div class="t m0 x1 h7 y25 ff7 fs4 fc0 sc1 ls1a ws10">#include <span class="_ _14"> </span>&lt;pic1687x.h&gt; </div><div class="t m0 x1 h7 y26 ff7 fs4 fc0 sc1 lsd ws0">/*<span class="ff6 ls2">&#35813;&#31243;&#24207;&#29992;&#20110;&#22312;<span class="_ _2"> </span><span class="ff7">8<span class="_"> </span></span>&#20010;<span class="_ _2"> </span></span><span class="lse">LED<span class="_"> </span><span class="ff6 ls2">&#19978;&#20381;&#27425;&#26174;&#31034;<span class="_ _2"> </span></span><span class="ls1b">1~8<span class="_"> </span><span class="ff6 ls2">&#31561;<span class="_ _2"> </span><span class="ff7">8<span class="_"> </span></span>&#20010;&#23383;&#31526;</span><span class="lsa">*/ </span></span></span></div><div class="t m0 x1 h7 y27 ff7 fs4 fc0 sc1 ls1c ws11">static volatile <span class="_ _6"></span>int table[20]={<span class="_ _6"></span>0xc0<span class="ff6 ls2 ws0">&#65292;<span class="_ _15"></span><span class="ff7 ls1d">0xf9<span class="ff6 ls2">&#65292;<span class="_ _15"></span><span class="ff7 ls1e">0xa4<span class="ff6 ls2">&#65292;<span class="_ _15"></span><span class="ff7 ls1e">0xb0<span class="ff6 ls2">&#65292;<span class="_ _15"></span><span class="ff7 ls1e">0x99<span class="ff6 ls2">&#65292;<span class="_ _15"></span><span class="ff7 ls1e">0x92<span class="ff6 ls2">&#65292;<span class="_ _15"></span><span class="ff7 ls1e">0x82<span class="ff6 ls2">&#65292;<span class="_ _15"></span><span class="ff7 ls1f">0XD8<span class="ff6 ls2">&#65292;<span class="_ _15"></span><span class="ff7 ls1e">0x80<span class="ff6 ls2">&#65292;<span class="_ _15"></span><span class="ff7 ls20">0x90<span class="ff6 ls2">&#65292;</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></div><div class="t m0 x1 h7 y28 ff7 fs4 fc0 sc1 ls1e ws0">0x88<span class="ff6 ls2">&#65292;</span>0x83<span class="ff6 ls2">&#65292;</span><span class="lsa">0xc6<span class="ff6 ls2">&#65292;</span>0xa1<span class="ff6 ls2">&#65292;</span></span>0x86<span class="ff6 ls2">&#65292;</span>0x8e<span class="ff6 ls2">&#65292;</span>0x7f<span class="ff6 ls2">&#65292;</span>0xbf<span class="ff6 ls2">&#65292;</span>0x89<span class="ff6 ls2">&#65292;</span><span class="ls21">0xf<span class="_ _6"></span>f}<span class="ff6 ls2">&#65307;<span class="ff7"> </span></span></span></div><div class="t m0 x1 h7 y29 ff7 fs4 fc0 sc1 ls1c ws12">volatile unsigned <span class="_ _16"> </span>char <span class="_ _17"> </span>data<span class="ff6 ls2 ws0">&#65307;<span class="ff7 lsf"> </span></span></div><div class="t m0 x1 h7 y2a ff7 fs4 fc0 sc1 ls22 ws13">#define POR<span class="_ _4"></span>T<span class="_ _3"></span>AIT(adr<span class="ff6 ls2 ws0">&#65292;</span><span class="ls16 ws14">bit) ((unsigned)(&amp;adr)*8+(bit)) <span class="_ _18"> </span>/*<span class="ff6 ls2 ws0">&#32477;&#23545;&#23547;&#22336;&#20301;&#25805;&#20316;&#25351;&#20196;<span class="ff7 lsa">*/ </span></span></span></div><div class="t m0 x1 h7 y2b ff7 fs4 fc0 sc1 ls23 ws15">static <span class="_ _19"> </span>bit POR<span class="_ _3"></span>T<span class="_ _4"></span>A_5 @ POR<span class="_ _3"></span>T<span class="_ _3"></span>AIT(POR<span class="_ _3"></span>T<span class="_ _4"></span>A<span class="ff6 ls2 ws0">&#65292;<span class="ff7 ls1e">5)</span>&#65307;<span class="ff7 lsf"> </span></span></div><div class="t m0 x1 h7 y2c ff7 fs4 fc0 sc1 ls12 ws0">/*spi<span class="_"> </span><span class="ff6 ls2">&#21021;&#22987;&#21270;&#23376;&#31243;&#24207;</span><span class="lsa">*/ </span></div><div class="t m0 x1 h7 y2d ff7 fs4 fc0 sc1 ls13 ws16">void <span class="_ _1a"> </span>SPIINIT() </div><div class="t m0 x1 h7 y2e ff7 fs4 fc0 sc1 ls2 ws0">{ </div><div class="t m0 x1 h7 y2f ff7 fs4 fc0 sc1 ls14 wsa"> PIR1=0<span class="ff6 ls2 ws0">&#65307;<span class="ff7 ls24"> <span class="_ _1b"></span> </span></span></div><div class="t m0 x1 h7 y30 ff7 fs4 fc0 sc1 ls15 wsc"> SSPCON=0x30<span class="ff6 ls2 ws0">&#65307;</span><span class="ls7 wsd"> <span class="_ _11"></span> /* <span class="_ _9"></span>SSPEN=1<span class="ff6 ls2 ws0">&#65307;<span class="ff7 ls16">CKP=0 <span class="_"> </span></span>&#65292;</span><span class="ls17 wse"> FOSC/4 <span class="_ _12"></span>*/ </span></span></div><div class="t m0 x1 h7 y31 ff7 fs4 fc0 sc1 ls2 ws5"> SSPST<span class="_ _3"></span>A<span class="_ _13"></span>T=0xC0<span class="ff6 ws0">&#65307;<span class="ff7"> </span></span></div><div class="t m0 x1 h7 y32 ff7 fs4 fc0 sc1 ls18 wsf"> TRISC=0x00<span class="ff6 ls2 ws0">&#65307;<span class="ff7 ls9"> <span class="_ _b"></span> /<span class="_ _9"></span>*<span class="_ _9"></span>S<span class="_ _9"></span>D<span class="_ _9"></span>O<span class="_ _a"></span><span class="ff6 ls2">&#24341;&#33050;&#20026;&#36755;&#20986;&#65292;<span class="ff7 ls19">SCK<span class="_"> </span></span>&#24341;&#33050;&#20026;&#36755;&#20986;<span class="ff7 lsa">*/ </span></span></span></span></div><div class="t m0 x1 h7 y33 ff7 fs4 fc0 sc1 ls2 ws0">} </div><div class="t m0 x1 h7 y34 ff7 fs4 fc0 sc1 lsd ws0">/*<span class="ff6 ls2">&#31995;&#32479;&#21508;&#36755;&#20837;&#36755;&#20986;&#21475;&#21021;&#22987;&#21270;&#23376;&#31243;&#24207;</span><span class="lsa">*/ </span></div><div class="t m0 x1 h7 y35 ff7 fs4 fc0 sc1 ls25 ws17">void <span class="_ _1a"> </span>initial() </div><div class="t m0 x1 h7 y36 ff7 fs4 fc0 sc1 ls2 ws0">{ </div><div class="t m0 x4 h7 y37 ff7 fs4 fc0 sc1 ls8 ws0">TRISA=0x00<span class="ff6 ls2">&#65307;</span><span class="ls9"> <span class="_ _d"></span> /<span class="_ _9"></span>*<span class="_ _9"></span>A<span class="_ _a"></span><span class="ff6 ls2">&#21475;&#35774;&#32622;&#20026;&#36755;&#20986;<span class="ff7 lsa">*/ </span></span></span></div><div class="t m0 x1 h7 y38 ff7 fs4 fc0 sc1 ls8 ws4"> INTCON=0x00<span class="ff6 ls2 ws0">&#65307;<span class="ff7 ls9"> <span class="_ _11"></span> /<span class="_ _9"></span>*<span class="_ _9"></span><span class="ff6 ls2">&#20851;&#38381;&#25152;&#26377;&#20013;&#26029;<span class="ff7 lsa">*/ </span></span></span></span></div><div class="t m0 x1 h7 y39 ff7 fs4 fc0 sc1 ls14 wsa"> POR<span class="_ _3"></span>T<span class="_ _4"></span>A_5=0<span class="ff6 ls2 ws0">&#65307;<span class="ff7 ls9"> <span class="_ _15"></span> /<span class="_ _9"></span>*<span class="_ _9"></span>L<span class="_ _9"></span>A<span class="_ _9"></span>C<span class="_ _9"></span>K<span class="_ _a"></span><span class="ff6 ls2">&#36865;&#20302;&#30005;&#24179;&#65292;&#20026;&#38145;&#23384;&#20570;&#20934;&#22791;<span class="ff7 lsa">*/ </span></span></span></span></div></div><div class="pi" data-data='{"ctm":[1.611639,0.000000,0.000000,1.611639,0.000000,0.000000]}'></div></div> </body> </html>
评论
    相关推荐
    • AVR单片机C语言
      AVR单片机C语言
    • 单片机C语言编程课件
      单片机C语言编程与实践课件,里面有各种程序实现的代码 实现的方法 AD转换器 wire总线 串行通信 按键接口 中断定时 数码管显示等
    • 经典单片机C语言教程
      经典单片机C语言教程,经典不容错过! 经典单片机C语言教程,经典不容错过! 经典单片机C语言教程,经典不容错过! 经典单片机C语言教程,经典不容错过! 经典单片机C语言教程,经典不容错过!
    • 单片机 C语言 课件
      单片机C语言 课件单片机C语言 课件单片机C语言 课件
    • 单片机C语言编程
      这是本单片机开发入门书籍初学者通过这本入门书籍能够熟练掌握单片机的基本编程技能
    • 单片机C语言资料
      该文件为单片机相关资料,里边涉及了与单片机有关的C语言编程,资料分为几个部分,内容较为详细,有意学习单片机编程的同学的以下载学习。
    • 单片机C语言开发
      本文对C语言开发特别是对在汇编语言有一定经验的工作人员想转入潜入式C开发有一定帮助.
    • 单片机c语言教程 单片机c语言教程下
      单片机C语言教程 单片机关于C语言教程 (下) 接单片机关于C语言教程 (上) 教程简单明了 易于上手 可谓速成班
    • 单片机 C语言进阶
      总共7章可使你对单片机有更深入的了解~对单片机C语言有基础想对单片机C语言的朋友可以参考一下
    • GaussDB_100_1.0.1-DATABASE-REDHAT-64bit.tar.gz
      guassdb100在redhat上安装包,单机部署的包,安装步骤请看我的文中介绍,经过大量实验搭建总结出来的文档