日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當(dāng)前位置:首頁(yè) > 單片機(jī) > 單片機(jī)
[導(dǎo)讀]實(shí)現(xiàn)串口輸出,以及將接收到的信息發(fā)送回。利用PC機(jī)串口測(cè)試,正常。kit3、MPLAB X IDE Version 1.85;target PIC16F877A最小系統(tǒng)。#include #define uchar unsigned char#define uint unsigned int// CONFIG#pragma

實(shí)現(xiàn)串口輸出,以及將接收到的信息發(fā)送回。

利用PC機(jī)串口測(cè)試,正常。

kit3、MPLAB X IDE Version 1.85;target PIC16F877A最小系統(tǒng)。

#include

#define uchar unsigned char

#define uint unsigned int

// CONFIG

#pragma config FOSC = HS // Oscillator Selection bits (HS oscillator)

#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)

#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)

#pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled)

#pragma config LVP = ON // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3/PGM pin has PGM function; low-voltage programming enabled)

#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)

#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)

#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)

//main.c

void uart_init(void);

void uart_send_byte(char uart_data);

char uart_receive_byte(void);

void delay(void);

/***********************************************/

char uart_current_data;

char uart_last_data;

char evm_info[]="Welcom to use PIC16F877-EVM-BOARD-V1.0";

/*********************************************************************/

void main(void)

{

unsigned char i,j;

TRISB = 0x00+(0x01<<5); //初始化端口B,RB5為輸入口,其余為輸出口

TRISC = 0x80; // bit7 rx input bit6 tx output初始化端口C的方向控制寄存器(

//對(duì)應(yīng)的比特為0是輸出口,比特為1輸入口)

TRISD = 0x00; //初始化D口

TRISE = 0x00; //初始化E口

ADCON1= 0x06; //端口都為數(shù)字口

TRISA = 0x00; //設(shè)置A口均為輸出口

OPTION_REG &= (~(0x01<<7)); //

PORTA = 0xff; //初始化端口寄存器

PORTB = 0xff&(~(0x01<<5));

PORTC = 0xff;

PORTD = 0xff;

PORTE = 0xff;

uart_init(); //初始化PIC16F877串行通訊接口

for(i=0;i<38;i++)

{

uart_send_byte(evm_info[i]);

}

uart_send_byte(0x0d); //將回車鍵第一字符給PC

uart_send_byte(0x0a); //將回車鍵第二字符給PC

for(;;) //程序主循環(huán)

{

uart_current_data=uart_receive_byte(); //接收一個(gè)字符,沒(méi)有收到字符,返回0x00

if( uart_current_data!=0x00 && uart_current_data!=0x0d &&

uart_current_data!=0x0a)

{

uart_send_byte(uart_current_data); //將字符發(fā)回PC

uart_last_data=uart_current_data; //暫存當(dāng)前的字符

}

else if(uart_current_data==0x0d) //回車鍵字符判斷?

{

uart_last_data=uart_current_data; //暫存回車鍵字符第一字符

}

else if(uart_current_data==0x0a && uart_last_data==0x0d)//收到了正

//確的回車鍵?

{

uart_send_byte(0x0d); //將回車鍵第一字符給PC

uart_send_byte(0x0a); //將回車鍵第二字符給PC

uart_last_data=0x00;

}

}

}

/************************************************/

void delay(void)

{

unsigned int i;

for(i=0;i<500;i++);

}

void interrupt isr_service(void) //中斷服務(wù)程序

{

if(T0IE && T0IF)

{

T0IF = 0; //在此加入TMR0中斷服務(wù)

}

if (TMR1IE && TMR1IF) //判TMR1中斷

{

TMR1IF=0; //在此加入TMR1中斷服務(wù)

}

} //中斷結(jié)束并返回

/************************************************/

void uart_init(void)

{

SPBRG=0x4d; //設(shè)置通訊波特率為9600/秒

SPEN=1; //1 = Serial port enabled (configures RC7/RX/DT and

// RC6/TX/CK pins as serial port pins)

RX9=0; //0 = Selects 8-bit reception

SYNC=0; //Asynchronous mode

BRGH=1; //1 = High speed

TX9=0; //0 = Selects 8-bit transmission

TXEN=1; //1 = Transmit enabled

CREN=1;

}

/***********************************************/

void uart_send_byte(char uart_data)

{

TXREG=uart_data;

while(1)

{ //等待發(fā)送完畢

if(TRMT==1) break ; // 使用if(TXIF == 1) break 時(shí),會(huì)導(dǎo)致發(fā)送數(shù)據(jù)的丟失

}

}

/***********************************************/

char uart_receive_byte(void)

{

char result=0;

if(RCIF==1) //判是否收到了數(shù)據(jù)?

{

result=RCREG; //讀取接收到的數(shù)據(jù)

}

return(result);

}

/***********************************************/

本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請(qǐng)聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請(qǐng)及時(shí)聯(lián)系本站刪除。
換一批
延伸閱讀

//軟件思路:選擇RAO做為模擬輸入通道; // 連續(xù)轉(zhuǎn)換4次再求平均值做為轉(zhuǎn)換結(jié)果 // 最后結(jié)構(gòu)只取低8位 // 結(jié)果送數(shù)碼管的低3位顯示 #include //包含內(nèi)部資源預(yù)定義...

關(guān)鍵字: ad轉(zhuǎn)換 pic16f877a picc

unsigned char eeprom_read(unsigned char addr);void eeprom_write(unsigned char addr, unsigned char value);這兩個(gè)函數(shù)...

關(guān)鍵字: pic16f877a eeprom使用

//*****************電子園PIC16F877A開(kāi)發(fā)板 SPI總線驅(qū)動(dòng)74595實(shí)驗(yàn)***************////CKP=0; 空閑為低電平//CKP=1; 空閑為高電平//STAT_CKE=0;...

關(guān)鍵字: pic16f877a spi總線 驅(qū)動(dòng)74595

用c語(yǔ)言寫的一個(gè)時(shí)鬧鐘程序單片機(jī)用16F877,主時(shí)鐘用20MHz,用32768作定時(shí)時(shí)間。可以實(shí)現(xiàn)2路定鬧,每一路都可分別設(shè)置和開(kāi)關(guān),采用4x4鍵盤,16x2的字符型LCD顯示。連線在程序開(kāi)頭有...

關(guān)鍵字: pic16f877a 時(shí)鐘 程序 語(yǔ)言

/****************************************************標(biāo)題:萬(wàn)年歷**說(shuō)明:包含文件,*****************************...

關(guān)鍵字: pic16f877a 萬(wàn)年歷 程序

//數(shù)碼管顯示//★★★★★★★★★數(shù)碼管顯示★★★★★★★★★★★\\\\ //單征機(jī)型號(hào):PIC16F877A //功能描述:采用動(dòng)態(tài)掃描方式,初始時(shí)顯示123,當(dāng)按下RB0時(shí),數(shù)值加一,當(dāng)按下RB1時(shí),數(shù)值減一...

關(guān)鍵字: pic16f877a 數(shù)碼管顯示

/************************************************PIC16F877A 內(nèi)部EEPROM讀寫實(shí)驗(yàn)*******Author:hnrainDate:2010-12-26Ver...

關(guān)鍵字: pic16f877a 內(nèi)部eeprom 內(nèi)部函數(shù) 讀寫實(shí)驗(yàn)

/*Capture mode時(shí),外部CCP1事件觸發(fā)后,CCPR1H和CCPR1L將獲取Timer1的TMR1H和TMR1L中的數(shù)值對(duì)于CCP1的觸發(fā)事件,設(shè)置鍵CCP1Con中的相應(yīng)位CCP1M3--CCP1M0CCP...

關(guān)鍵字: capture mode pic16f877a

PIR1 Register The PIR1 register contains the individual flag bits for the peripheralinterrupts.PIR1 REGISTERPS...

關(guān)鍵字: pic16f877a 單片機(jī) spi學(xué)習(xí)
關(guān)閉