導航:首頁 > 編程語言 > 16c554程序

16c554程序

發布時間:2024-03-29 12:28:21

⑴ 單片機上寫的串口程序是什麼意思啊

單片機(MCU)也就是人們所說的微處理器。可以理解為應用於嵌入式或工業控制上的小型CPU。與我們PC中CPU不同的是,單片機是一個處理器核與一些人們常用到的硬體資源封裝到一片晶元里了。

例如你這里說到的串口,它是工控中最常使用到的通信方式之一,幾乎所有的MCU內都會集成串口資源。而PC中串口一般是在主板上外擴一片16C554晶元擴屏出來的。當然在需要多串口的場合,MCU也可以通過控制16C55x來擴屏出串口。

你提到的TMOD,SCON,SBUF是C51/52系列單片機中的與串口控制相關的寄存器。
為了簡單說明,給你一段程序,我加上注釋給你:
void InitComm() //初始化C51單片機串口
{//設置定時器1為波特率發生器
PCON |= 0x80; //設置波特率加倍
TMOD |= 0x20; //設置定時器1為方式2運行
TH1 = (unsigned char)(0xXXXX); //設置定時常數。一般0xXXXX由系統晶振與通信目標波特率所定.
TR1 = 1; //啟動定時器1
SCON = 0x50; //串列口方式1,允許串列接收。
ES = 1; //允許串口中斷
}

//串列中斷服務程序
void it_comm(void ) interrupt 4 using 1
{
if (RI)
{//接收數據中斷
RI = 0;
}
if (TI)
{//發送數據中斷
TI = 0;
}
}
////////////////////////
補充:
RS232協議是串口通信協議,它是由硬體自動完成的。也就是說,像開始位,停止位,效驗等等,都是由硬體自動加上去的。對於程序員來講,可以認為是透明的。只需要初始化時定義好就可以了。
你提到的MAX232隻是做電平轉換用的。和RS232協議沒有直接關系。

⑵ 我用mplab 編寫一個pic18f252的c 程序,創建時顯示:can't open "pic.h" head file such director

搜索欄里找PIC.H
你看看是這個不:
#ifndef _PIC_H
#define _PIC_H
#if defined(_10F200) || defined(_10F202) ||\\
defined(_10F204) || defined(_10F206)
#include <pic10f20x.h>
#endif
#if defined(_12C508) || defined(_12C509) ||\\
defined(_12F508) || defined(_12F509) ||\\
defined(_12C508A) || defined(_12C509A) ||\\
defined(_12CE518) || defined(_12CE519) ||\\
defined(_12C509AG) || defined(_12C509AF) ||\\
defined(_12CR509A) || defined(_RF509AG) ||\\
defined(_RF509AF)
#include <pic125xx.h>
#endif
#if defined(_16C432) || defined(_16C433)
#include <43x.h>
#endif
#if defined(_16C52) || defined(_16C54) || defined(_16C54A) ||\\
defined(_16C54B) || defined(_16C54C) || defined(_16CR54A) ||\\
defined(_16CR54B) || defined(_16CR54C) || defined(_16C55) ||\\
defined(_16C55A) || defined(_16C56) || defined(_16C56A) ||\\
defined(_16CR56A) || defined(_16C57) || defined(_16C57C) ||\\
defined(_16CR57B) || defined(_16CR57C) || defined(_16C58A) ||\\
defined(_16C58B) || defined(_16CR58A) || defined(_16CR58B) ||\\
defined(_16C58) || defined(_16HV540)
#include <5x.h>
#endif
#if defined(_16F54) || defined(_16F57)
#include <f5x.h>
#endif
#if defined(_12C671) || defined(_12C672) ||\\
defined(_12CE673) || defined(_12CE674)
#include <pic1267x.h>
#endif
#if defined(_12F629) || defined(_12F675)
#include <pic12f6x.h>
#endif
#if defined(_12F683)
#include <pic12f683.h>
#endif
#if defined(_12F675F) || defined(_12F675H) || defined(_12F675K)
#include <pic12rf675.h>
#endif
#if defined(_16C505) || defined(_16F505)
#include <505.h>
#endif
#ifdef _14000
#include <pic14000.h>
#endif
#if defined(_16C554) || defined(_16C556) || defined(_16C557) || \\
defined(_16C558) || defined(_16C554A) || defined(_16C556A) || \\
defined(_16C558A)
#include <55x.h>
#endif
#ifdef _16C61
#include <61.h>
#endif
#if defined(_16C62) || defined(_16C62A) || defined(_16CR62) ||\\
defined(_16C62B)
#include <62.h>
#endif
#if defined(_16C620) || defined(_16C621) || defined(_16C622) ||\\
defined(_16C620A) || defined(_16C621A) || defined(_16C622A) ||\\
defined(_16CE623) || defined(_16CE624) || defined(_16CE625) ||\\
defined(_16CR620A)
#include <62x.h>
#endif
#if defined(_16C64) || defined(_16C64A) || defined(_16CR64)
#include <64.h>
#endif
#if defined(_16C641) || defined(_16C642) ||\\
defined(_16C661) || defined(_16C662)
#include <6xx.h>
#endif
#if defined(_16C65) || defined(_16C65A) || defined(_16CR65)
#include <65.h>
#endif
#if defined(_16C66) || defined(_16C67)
#include <6x.h>
#endif
#if defined(_16C71) || defined(_16C710) || defined(_16C711)
#include <71x.h>
#endif
#if defined(_16C712) || defined(_16C715) || defined(_16C716)
#include <715.h>
#endif
#if defined(_16C72) || defined(_16C72A) || defined(_16CR72)
#include <72.h>
#endif
#if defined(_16C73) || defined(_16C73A) ||\\
defined(_16C74) || defined(_16C74A) ||\\
defined(_16C63) || defined(_16CR63) || defined(_16C63A) ||\\
defined(_16C65B) || defined(_16C73B) || defined(_16C74B) ||\\
defined(_16LC74B)
#include <74.h>
#endif
#if defined(_16C76) || defined(_16C77)
#include <77.h>
#endif
#if defined(_16C773) || defined(_16C774) || defined(_16C770) ||\\
defined(_16C771) || defined(_16C717) || defined(_16C745) ||\\
defined(_16C765)
#include <77x.h>
#endif
#if defined(_16C781) || defined(_16C782)
#include <78x.h>
#endif
#if defined(_16F627) || defined(_16F628)
#include <f6x.h>
#endif
#if defined(_16F627A) || defined(_16F628A) || defined(_16F648A)
#include <f62xa.h>
#endif
#if defined(_16F630) || defined(_16F676)
#include <630.h>
#endif
#if defined(_12F635) || defined(_16F636)
#include <f636.h>
#endif
#if defined(_16F684)
#include <f684.h>
#endif
#if defined(_16F688)
#include <f688.h>
#endif
#if defined(_16F83) || defined(_16CR83) || defined(_16C84) || \\
defined(_16F84) || defined(_16F84A) || defined(_16CR84)
#include <84.h>
#endif
#if defined(_16F87) || defined(_16F88)
#include <f87.h>
#endif
#if defined(_16F873) || defined(_16F874) ||\\
defined(_16F876) || defined(_16F877) ||\\
defined(_16F872) || defined(_16F871) ||\\
defined(_16F870)
#include <87x.h>
#endif
#if defined(_16F873A) || defined(_16F874A) ||\\
defined(_16F876A) || defined(_16F877A)
#include <8xa.h>
#endif
#if defined(_16F72) ||\\
defined(_16F73) || defined(_16F74) ||\\
defined(_16F76) || defined(_16F77)
#include <f7x.h>
#endif
#if defined(_16F716)
#include <f716.h>
#endif
#if defined(_16F737) || defined(_16F747) ||\\
defined(_16F767) || defined(_16F777)
#include <f7x7.h>
#endif
#if defined(_16F818) || defined(_16F819)
#include <f81x.h>
#endif
#if defined(_16C923) || defined(_16C924) ||\\
defined(_16C925) || defined(_16C926)
#include <9xx.h>
#endif
#if defined(_7C695X)
#include <pic7695x.h>
#endif
#if defined(_16C99) || defined (_16C99C)
#include <99.h>
#endif
#if defined(_17C42) || defined(_17C42A) || defined(_17CR42) ||\\
defined(_17C43) || defined(_17CR43) || defined(_17C44)
#include <pic174x.h>
#endif
#if defined(_17C752) || defined(_17C756) || defined(_17C756A) ||\\
defined(_17C762) || defined(_17C766)
#include <pic177xx.h>

#endif

#define CLRWDT() asm("clrwdt")
#define SLEEP() asm("sleep")
#define NOP() asm("nop")
#define ___mkstr1(x) #x
#define ___mkstr(x) ___mkstr1(x)
#define __CONFIG(x) asm("\\tpsect config,class=CONFIG,delta=2");\\
asm("\\tdw "___mkstr(x))
#define __IDLOC(w) asm("\\tpsect idloc,class=IDLOC,delta=2");\\
asm("\\tglobal\\tidloc_word"); \\
asm("idloc_word"); \\
asm("\\tirpc\\t__arg," ___mkstr(w)); \\
asm("\\tdw 0&__arg&h"); \\
asm("\\tendm")
#if EEPROM_SIZE > 0
#define __EEPROM_DATA(a, b, c, d, e, f, g, h) \\
asm("\\tpsect eeprom_data,class=EEDATA,delta=2"); \\
asm("\\tdb\\t" ___mkstr(a) "," ___mkstr(b) "," ___mkstr(c) "," ___mkstr(d) "," \\
___mkstr(e) "," ___mkstr(f) "," ___mkstr(g) "," ___mkstr(h))
#endif
/***********************************************************************
**** FLASH memory read/write/erase macros and function definitions ****
***********************************************************************
* Notes:
* __FLASHTYPE == 0 defined in devices that can only read flash memory - cannot write eg. 16F777
* __FLASHTYPE == 1 defined in traditional devices that can write 1 word at a time eg. 16F877
* __FLASHTYPE == 2 defined in devices that can only write in 4 word blocks eg. 16F877A
* __FLASHTYPE == 3 defined in devices requiring 32-word block erasure before writing eg. 16F87
* __FLASHTYPE == undefined if device can neither read nor write program memory
*/
// macro FLASH_READ returns a word stored at a flash address
#if defined(__FLASHTYPE)
extern unsigned char flash_read(unsigned short addr);
#if EEPROM_SIZE > 0
#define FLASH_READ(addr) \\
(EEADR=(addr)&0xff, \\
EEADRH=(addr)>>8, \\
WREN=0, \\
EECON1 |= 0x80, \\
RD=1, \\
DC=0, \\
DC=0, \\
(EEDATH << 8) | EEDATA)
#else // FLASH_READ without EEPROM
#define FLASH_READ(addr) \\
(EEADR=(addr)&0xff, \\
EEADRH=(addr)>>8, \\
RD=1, \\
DC=0, \\
DC=0, \\
(EEDATH << 8) | EEDATA)
#endif
#endif // end FLASH_READ
// macro FLASH_WRITE used when writing only one word of data
#if __FLASHTYPE==2 || __FLASHTYPE==3
#define FLASH_WRITE(addr,data) \\
do{ \\
unsigned short x=data; \\
flash_((const unsigned char *)&x,1,addr); \\
}while(0)
extern void flash_(const unsigned char * source_addr,unsigned char length,unsigned short dest_addr);
#elif __FLASHTYPE==1
#define FLASH_WRITE(addr, value) \\
EEADR=((addr)&0xff); \\
EEADRH=((addr)>>8); \\
EEDATH=((value)>>8); \\
EEDATA=((value)&0xff); \\
EECON1 |= 0x80; \\
WREN=1; \\
EECON2 = 0x55; \\
EECON2 = 0xaa; \\
WR=1; \\
asm("nop"); \\
asm("nop"); \\
WREN=0
#endif // end FLASH_WRITE
// macro FLASH_ERASE used to clear a 32-Byte sector of flash
#if __FLASHTYPE==3
#define FLASH_ERASE(addr) \\
while(WR)continue; \\
EEADR=((addr)&0xFF); \\
EEADRH=((addr>>8)&0xFF); \\
EECON1=0x94; \\
CARRY=0;if(GIE)CARRY=1;GIE=0;\\
EECON2=0x55;EECON2=0xAA;WR=1; \\
asm("\\tNOP"); \\
if(CARRY)GIE=1
// library function version
extern void flash_erase(unsigned short addr);
#endif // end FLASH_ERASE
/***********************************************************************/
/****** EEPROM memory read/write macros and function definitions *******/
/***********************************************************************/
#if EEPROM_SIZE > 0
#ifdef __FLASHTYPE
// macro versions of EEPROM write and read
#define EEPROM_WRITE(addr, value) \\
while(WR)continue;EEADR=(addr);EEDATA=(value); \\
EECON1&=0x7F;CARRY=0;if(GIE)CARRY=1;GIE=0; \\
WREN=1;EECON2=0x55;EECON2=0xAA;WR=1;WREN=0; \\
if(CARRY)GIE=1
#define EEPROM_READ(addr) ((EEADR=(addr)),(EECON1&=0x7F),(RD=1),EEDATA)
#else // else doesn\'t write flash
#define EEPROM_WRITE(addr, value) \\
while(WR)continue;EEADR=(addr);EEDATA=(value); \\
CARRY=0;if(GIE)CARRY=1;GIE=0; \\
WREN=1;EECON2=0x55;EECON2=0xAA;WR=1;WREN=0; \\
if(CARRY)GIE=1
#define EEPROM_READ(addr) ((EEADR=(addr)),(RD=1),EEDATA)
#endif
/* library function versions */
extern void eeprom_write(unsigned char addr, unsigned char value);
extern unsigned char eeprom_read(unsigned char addr);
#endif // end EEPROM routines
/****************************************************************/
/****** Global interrupt enable/disable macro definitions *******/
/****************************************************************/
#ifdef _PIC16
#ifndef ei
#define ei() (GLINTD = 0) // interrupt disable bit
#endif ei
#if defined(_17C42)
#ifndef di
#define di() { do { GLINTD = 1; } while ( GLINTD == 0 ); } // disable interrupt bit
#endif di
#else
#ifndef di
#define di() (GLINTD = 1) // interrupt disable bit
#endif di
#endif
#elif defined _PIC14

#ifndef ei
#define ei() (GIE = 1) // interrupt enable bit
#endif ei
#if defined(_14000) || defined(_16C61) || defined(_16C62) ||\\
defined(_16C63) || defined(_16C63A) || defined(_16C64) ||\\
defined(_16C65) || defined(_16C65B) || defined(_16C71) ||\\
defined(_16C73) || defined(_16C73B) || defined(_16C74) ||\\
defined(_16C74B) || defined(_16C84) || defined(_16C745) ||\\
defined(_16C765) || defined(_16LC74B)
#ifndef di
#define di() { do { GIE = 0; } while ( GIE == 1 ); } // disable interrupt bit
#endif di
#else
#ifndef di
#define di() (GIE = 0) // interrupt enable bit
#endif di
#endif

#endif
#endif /* _PIC_H */

閱讀全文

與16c554程序相關的資料

熱點內容
怎麼用手機看wlan密碼 瀏覽:745
奧維地圖導入的文件在哪裡 瀏覽:364
sdltrados2014教程 瀏覽:43
培訓制度文件在哪裡找 瀏覽:601
勒索病毒防疫工具 瀏覽:861
win10c不能打開 瀏覽:375
xfplay影音先鋒蘋果版 瀏覽:597
兩個文件打開兩個word 瀏覽:921
蘋果6s桌面圖標輕微抖動 瀏覽:326
如何刪除手機中看不見的臨時文件 瀏覽:469
安卓412原生鎖屏apk 瀏覽:464
書加加緩存文件在哪裡 瀏覽:635
dock是word文件嗎 瀏覽:267
社保公司新辦去哪個網站下載資料 瀏覽:640
三維標注數據怎麼填寫 瀏覽:765
數據線斷在哪裡取出來 瀏覽:522
word最好的文件 瀏覽:345
大數據聚類資料庫 瀏覽:247
網站關停域名怎麼注銷 瀏覽:456
適合微信閱讀的手機報 瀏覽:114

友情鏈接