一、pic單片機與51的區別在哪
pic單片機在日常中使用頻率較高,與pic單片機具備同等地位的還有51單片機,那(nei)么(me)pic單(dan)片機(ji)和(he)51單(dan)片機(ji)有什么(me)區別呢?
1、總線結構區別
51單(dan)片(pian)(pian)機(ji)的(de)總(zong)線(xian)結(jie)(jie)構是(shi)(shi)馮-諾依曼(man)型(xing),計(ji)算機(ji)在同一(yi)(yi)個存儲空間(jian)取(qu)指令(ling)和(he)數(shu)據(ju)(ju),兩者不能同時進行;而PIC單(dan)片(pian)(pian)機(ji)的(de)總(zong)線(xian)結(jie)(jie)構是(shi)(shi)哈(ha)佛結(jie)(jie)構,指令(ling)和(he)數(shu)據(ju)(ju)空間(jian)是(shi)(shi)完(wan)全分(fen)開的(de),一(yi)(yi)個用(yong)于(yu)指令(ling),一(yi)(yi)個用(yong)于(yu)數(shu)據(ju)(ju),由于(yu)可(ke)以(yi)對程(cheng)序(xu)和(he)數(shu)據(ju)(ju)同時進行訪(fang)問,所以(yi)提高了數(shu)據(ju)(ju)傳輸效率。正因為在PIC系列單(dan)片(pian)(pian)機(ji)中(zhong)采用(yong)了哈(ha)佛雙總(zong)線(xian)結(jie)(jie)構,所以(yi)與常見的(de)微(wei)控制器不同的(de)一(yi)(yi)點是(shi)(shi):程(cheng)序(xu)和(he)數(shu)據(ju)(ju)總(zong)線(xian)可(ke)以(yi)采用(yong)不同的(de)寬度。數(shu)據(ju)(ju)總(zong)線(xian)都是(shi)(shi)8位(wei)的(de),但(dan)指令(ling)總(zong)線(xian)位(wei)數(shu)分(fen)別位(wei)12、14、16位(wei)。
2、寄存器組區別
PIC單(dan)片機(ji)的所有寄(ji)存器(qi),包括I/O口,定時(shi)器(qi)和程序(xu)計數器(qi)等都(dou)采用RAM結構形式(shi),而(er)且都(dou)只需要一個(ge)指令周期(qi)(qi)就可以(yi)完成訪問和操作(zuo);而(er)51單(dan)片機(ji)需要兩個(ge)或兩個(ge)以(yi)上的周期(qi)(qi)才能改變寄(ji)存器(qi)的內容。
3、流水線結構區別
51單片(pian)機的取(qu)(qu)指(zhi)(zhi)和執(zhi)(zhi)(zhi)行(xing)采(cai)用單指(zhi)(zhi)令流水(shui)線結(jie)構,即取(qu)(qu)一條(tiao)指(zhi)(zhi)令,執(zhi)(zhi)(zhi)行(xing)完(wan)后再取(qu)(qu)下一條(tiao)指(zhi)(zhi)令;而PIC單片(pian)機的取(qu)(qu)指(zhi)(zhi)和執(zhi)(zhi)(zhi)行(xing)采(cai)用雙指(zhi)(zhi)令流水(shui)線結(jie)構,當(dang)一條(tiao)指(zhi)(zhi)令被執(zhi)(zhi)(zhi)行(xing)時,允許(xu)下一條(tiao)指(zhi)(zhi)令同時被取(qu)(qu)出,這(zhe)樣就實現(xian)了(le)單周(zhou)期指(zhi)(zhi)令。
二、pic單片機和51單片機哪個好
pic單(dan)片(pian)(pian)(pian)(pian)機和51單(dan)片(pian)(pian)(pian)(pian)機相比,各有(you)各的優缺(que)點,并(bing)不一(yi)定哪種(zhong)單(dan)片(pian)(pian)(pian)(pian)機更好,下(xia)面為大家對比一(yi)下(xia)兩種(zhong)單(dan)片(pian)(pian)(pian)(pian)機的優劣勢:
1、51單片機的優缺點
(1)優點
51單片(pian)(pian)機的(de)(de)優點是它(ta)從內(nei)部的(de)(de)硬(ying)件到軟件有一套完整(zheng)的(de)(de)按(an)位(wei)(wei)(wei)(wei)(wei)操作(zuo)系(xi)統,它(ta)的(de)(de)處(chu)(chu)理對(dui)象不是字(zi)或(huo)字(zi)節(jie)而是位(wei)(wei)(wei)(wei)(wei),因此它(ta)不光能(neng)(neng)(neng)對(dui)片(pian)(pian)內(nei)某些特殊功能(neng)(neng)(neng)寄存(cun)器(qi)的(de)(de)某位(wei)(wei)(wei)(wei)(wei)進(jin)行處(chu)(chu)理,如傳送、置(zhi)位(wei)(wei)(wei)(wei)(wei)、清零、測試等,還能(neng)(neng)(neng)進(jin)行位(wei)(wei)(wei)(wei)(wei)的(de)(de)邏(luo)輯(ji)運算,其(qi)功能(neng)(neng)(neng)十(shi)分完備(bei),使(shi)用(yong)(yong)起來(lai)得心應手(shou)。雖然其(qi)他種類的(de)(de)單片(pian)(pian)機也具有位(wei)(wei)(wei)(wei)(wei)處(chu)(chu)理功能(neng)(neng)(neng),但能(neng)(neng)(neng)進(jin)行位(wei)(wei)(wei)(wei)(wei)邏(luo)輯(ji)運算的(de)(de)實屬少見。51單片(pian)(pian)機在(zai)片(pian)(pian)內(nei)RAM區間(jian)還特別開辟了一個雙重(zhong)功能(neng)(neng)(neng)的(de)(de)地(di)址(zhi)區間(jian),十(shi)六個字(zi)節(jie),單元地(di)址(zhi)20H~2FH,它(ta)既可作(zuo)字(zi)節(jie)處(chu)(chu)理,也可作(zuo)位(wei)(wei)(wei)(wei)(wei)處(chu)(chu)理(作(zuo)位(wei)(wei)(wei)(wei)(wei)處(chu)(chu)理時(shi),合(he)128個位(wei)(wei)(wei)(wei)(wei),相應位(wei)(wei)(wei)(wei)(wei)地(di)址(zhi)為(wei)OOH~7FH),使(shi)用(yong)(yong)極(ji)為(wei)靈活。這一功能(neng)(neng)(neng)無疑給使(shi)用(yong)(yong)者提供了極(ji)大的(de)(de)方便(bian)。
51單(dan)片機的另(ling)一個優(you)點(dian)是乘(cheng)(cheng)(cheng)(cheng)法(fa)和(he)除法(fa)指令,這(zhe)給編(bian)程也帶來了便利(li)。八(ba)(ba)位(wei)(wei)除以(yi)八(ba)(ba)位(wei)(wei)的除法(fa)指令,商為八(ba)(ba)位(wei)(wei),精度(du)嫌不(bu)夠,用得(de)不(bu)多。而八(ba)(ba)位(wei)(wei)乘(cheng)(cheng)(cheng)(cheng)八(ba)(ba)位(wei)(wei)的乘(cheng)(cheng)(cheng)(cheng)法(fa)指令,其積(ji)為十六位(wei)(wei),精度(du)還(huan)是能滿(man)足要求的,用的較多。作乘(cheng)(cheng)(cheng)(cheng)法(fa)時,只需一條指令即可。很多的八(ba)(ba)位(wei)(wei)單(dan)片機都不(bu)具備乘(cheng)(cheng)(cheng)(cheng)法(fa)功(gong)能,作乘(cheng)(cheng)(cheng)(cheng)法(fa)時還(huan)得(de)編(bian)上一段子程序調用,十分不(bu)便。
還有(you)就是,51系(xi)列(lie)的I/O腳(jiao)的設置和(he)使用非(fei)常簡單(dan),但高電平時無輸(shu)出能力,可(ke)謂有(you)利(li)有(you)弊。其他系(xi)列(lie)的單(dan)片機(如PIC系(xi)列(lie)、AVR系(xi)列(lie)等)對I/O口(kou)進行了改進,增加了方向寄存器(qi)以確定輸(shu)入或輸(shu)出,但使用也變得復雜。
(2)缺點
51單片機(ji)的(de)主要缺點(dian)是運行(xing)速度(du)過慢,當晶(jing)振頻率為(wei)12MHz時,機(ji)器(qi)周(zhou)期達(da)1μs,顯然適(shi)應(ying)不了現代高速運行(xing)的(de)需要。
2、pic單片機的優缺點
(1)優點
PIC單片機CPU采用RISC結構(gou),分別有33、35、58條(tiao)指(zhi)(zhi)令,屬精(jing)簡指(zhi)(zhi)令集,比51單片機(111條(tiao)指(zhi)(zhi)令)精(jing)簡很多,因此運行(xing)(xing)速(su)度(du)更快;它(ta)能(neng)使程序存儲器(qi)的訪問和數據存儲器(qi)的訪問并(bing)行(xing)(xing)處理,這(zhe)種指(zhi)(zhi)令流水線結構(gou),在一個周(zhou)期(qi)內完成兩部分工作(zuo),一是執行(xing)(xing)指(zhi)(zhi)令,二是從程序存儲器(qi)取出(chu)下一條(tiao)指(zhi)(zhi)令,這(zhe)樣(yang)總(zong)的看來(lai)每條(tiao)指(zhi)(zhi)令只需(xu)一個周(zhou)期(qi)(個別除(chu)外),這(zhe)也是高(gao)效率(lv)運行(xing)(xing)的原因之一。此外,它(ta)還(huan)具有低工作(zuo)電壓、低功耗、驅(qu)動能(neng)力強等特點。
另(ling)外,PIC系列(lie)單(dan)片機的(de)I/O口(kou)是(shi)雙(shuang)向的(de),其輸(shu)(shu)(shu)出(chu)(chu)電(dian)(dian)(dian)(dian)路(lu)為(wei)CMOS互補推挽輸(shu)(shu)(shu)出(chu)(chu)電(dian)(dian)(dian)(dian)路(lu)。I/O腳(jiao)增加了用于設置(zhi)輸(shu)(shu)(shu)入或輸(shu)(shu)(shu)出(chu)(chu)狀(zhuang)態的(de)方向寄存器,從(cong)而(er)解決了51系列(lie)I/O腳(jiao)為(wei)高(gao)電(dian)(dian)(dian)(dian)平(ping)時(shi)(shi)同為(wei)輸(shu)(shu)(shu)入和輸(shu)(shu)(shu)出(chu)(chu)的(de)狀(zhuang)態。當置(zhi)位1時(shi)(shi)為(wei)輸(shu)(shu)(shu)入狀(zhuang)態,且(qie)不管該腳(jiao)呈(cheng)高(gao)電(dian)(dian)(dian)(dian)平(ping)或低(di)電(dian)(dian)(dian)(dian)平(ping),對外均呈(cheng)高(gao)阻狀(zhuang)態;置(zhi)位0時(shi)(shi)為(wei)輸(shu)(shu)(shu)出(chu)(chu)狀(zhuang)態,不管該腳(jiao)為(wei)何(he)種電(dian)(dian)(dian)(dian)平(ping),均呈(cheng)低(di)阻狀(zhuang)態,有相當的(de)驅(qu)動能力,低(di)電(dian)(dian)(dian)(dian)平(ping)吸(xi)人(ren)電(dian)(dian)(dian)(dian)流(liu)達25mA,高(gao)電(dian)(dian)(dian)(dian)平(ping)輸(shu)(shu)(shu)出(chu)(chu)電(dian)(dian)(dian)(dian)流(liu)可達20mA。相對于51系列(lie)而(er)言,這是(shi)一個很大的(de)優點,它可以直接驅(qu)動數碼管顯示且(qie)外電(dian)(dian)(dian)(dian)路(lu)簡單(dan)。它的(de)A/D為(wei)10位,能滿足精度要求。
(2)缺點
在(zai)編程過(guo)程中,少(shao)不(bu)了要(yao)與專(zhuan)用(yong)寄存(cun)(cun)器打交道,得反復(fu)地選擇對應的(de)存(cun)(cun)儲(chu)體(ti),也即對狀態寄存(cun)(cun)器STATUS的(de)第6位(wei)(wei)(RPl)和(he)第5位(wei)(wei)(RPO)置位(wei)(wei)或清零(ling)。這多(duo)少(shao)給(gei)編程帶來了一些(xie)麻煩。對于pic單(dan)(dan)片機(ji)(ji),它的(de)位(wei)(wei)指(zhi)令操作(zuo)通(tong)常限制在(zai)存(cun)(cun)儲(chu)體(ti)0區(qu)間(00~7FH)。數(shu)據的(de)傳送(song)和(he)邏輯(ji)運算(suan)基本(ben)上都得通(tong)過(guo)工作(zuo)寄存(cun)(cun)器w(相(xiang)當于51單(dan)(dan)片機(ji)(ji)的(de)累加器A)來進行(xing),而(er)51單(dan)(dan)片機(ji)(ji)還(huan)可以通(tong)過(guo)寄存(cun)(cun)器相(xiang)互之間直接傳送(song),因而(er)PIC單(dan)(dan)片機(ji)(ji)的(de)瓶頸(jing)現(xian)象比51單(dan)(dan)片機(ji)(ji)還(huan)要(yao)嚴重,這在(zai)編程中很有感受。
綜合來看(kan),51單片機和pic單片機相(xiang)比,各有所長(chang),如何選擇主要看(kan)實際使用需(xu)要。