|
大家好:
今天我基于STC89C52單片機(jī)制作了一個(gè)公交車自動(dòng)報(bào)站系統(tǒng)的設(shè)計(jì)。
1, 實(shí)物照片
1AD31D2D5346378E21B0802DF602CD9C.png (615.63 KB, 下載次數(shù): 67)
下載附件
2019-8-28 19:13 上傳
2報(bào)站;接收模塊原理圖及PCB
51hei截圖_20190828101331.png (64.41 KB, 下載次數(shù): 52)
下載附件
2019-8-28 10:15 上傳
51hei截圖_20190828101355.png (33.91 KB, 下載次數(shù): 52)
下載附件
2019-8-28 10:15 上傳
51hei截圖_20190828101414.png (140.84 KB, 下載次數(shù): 55)
下載附件
2019-8-28 10:15 上傳
51hei截圖_20190828101433.png (140.75 KB, 下載次數(shù): 61)
下載附件
2019-8-28 10:15 上傳
3,發(fā)送信號(hào)整機(jī)程序
- #include <reg52.h>
- #define uint unsigned int
- #define uchar unsigned char
- uchar SUM = 0;
- #define BYTE_BIT0 0x01
- #define BYTE_BIT1 0x02
- #define BYTE_BIT2 0x04
- #define BYTE_BIT3 0x08
- #define BYTE_BIT4 0x10
- #define BYTE_BIT5 0x20
- #define BYTE_BIT6 0x40
- #define BYTE_BIT7 0x80
- ////////////SPI指令
- #define WC 0x00
- #define RC 0x10
- #define WTP 0x20
- #define RTP 0x21
- #define WTA 0x22
- #define RTA 0x23
- #define RRP 0x24
- bdata unsigned char DATA_BUF;
- #define DATA7 ((DATA_BUF&BYTE_BIT7) != 0)
- #define DATA0 ((DATA_BUF&BYTE_BIT0) != 0)
- sbit flag =DATA_BUF^7;
- sbit flag1 =DATA_BUF^0;
- #define TxRxBuf_Len 1
- unsigned char TxRxBuf[TxRxBuf_Len]=
- {
- 0x29
- };
- //配置口定義//
- sbit TXEN=P2^4;
- sbit TRX_CE=P2^3;
- sbit PWR=P2^5;
- sbit MISO=P2^1;
- sbit MOSI=P2^6;
- sbit SCK=P2^0;
- sbit CSN=P2^7;
- /////////////////////////////////////////////////////
- sbit AM=P2^2;
- sbit DR=P1^3;
- ///////////////////////////////////////////////////////
- sbit led1=P2^2;
- sbit led0=P2^3;
- sbit led2=P2^1;
- sbit led3=P2^0;
- ///////////////////////////////////////////////////////
- sbit KEY0=P1^0;
- sbit KEY1=P1^1;
- uchar seg[10]={0xC0,0xCF,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90}; //0~~9段碼
- //RF寄存器配置//
- unsigned char idata RFConf[11]=
- {
- 0x00, //配置命令//
- 0x4c, //CH_NO,配置頻段在423MHZ
- 0x0c, //輸出功率為10db,不重發(fā),節(jié)電為正常模式
- 0x44, //地址寬度設(shè)置,為4字節(jié)
- 0x04,0x04, //接收發(fā)送有效數(shù)據(jù)長(zhǎng)度為32字節(jié)
- 0xCC,0xCC,0xCC,0xCC, //接收地址
- 0x58, //CRC充許,8位CRC校驗(yàn),外部時(shí)鐘信號(hào)不使能,16M晶振
- };
- bit lcdbit;
- code TxAddress[4]={0xcc,0xcc,0xcc,0xcc};
- ///////////延時(shí)/////////////////
- static void Delay(uchar n)
- {
- uint i;
- while(n--)
- for(i=0;i<80;i++);
- }
- void SpiWrite(unsigned char send)
- {
- unsigned char i;
- DATA_BUF=send;
- for (i=0;i<8;i++)
- {
- if (DATA7) //總是發(fā)送最高位
- {
- MOSI=1;
- }
- else
- {
- MOSI=0;
- }
- SCK=1;
- DATA_BUF=DATA_BUF<<1;
- SCK=0;
- }
- }
- ////////////////初始化nRF905///////////////////
- void nRF905Init(void)
- {
- CSN=1; // Spi disable
- SCK=0; // Spi clock line init low
- DR=0; // Init DR for input
- AM=0; // Init AM for input
- // CD=0; // Init CD for input
- PWR=1; // nRF905 power on
- TRX_CE=0; // Set nRF905 in standby mode
- TXEN=0; // set radio in Rx mode
- }
- ////////初始化寄存器
- void Config905(void)
- {
- uchar i;
- CSN=0; // Spi enable for write a spi command
- //SpiWrite(WC); // Write config command寫(xiě)放配置命令
- for (i=0;i<11;i++) // Write configration words 寫(xiě)放配置字
- {
- SpiWrite(RFConf[i]);
- }
- CSN=1; // Disable Spi
- }
- /////////////發(fā)送數(shù)據(jù)
- void TxPacket(uchar *TxRxBuf)
- {
- uchar i;
- //Config905();
- CSN=0;
- SpiWrite(WTP); // Write payload command
- SpiWrite(TxRxBuf[0]); // Write 32 bytes Tx data
- CSN=1;
- Delay(1); // Spi disable
- CSN=0; // Spi enable for write a spi command
- SpiWrite(WTA); // Write address command
- for (i=0;i<4;i++) // Write 4 bytes address
- {
- SpiWrite(TxAddress[i]);
- }
- CSN=1; // Spi disable
- TRX_CE=1; // Set TRX_CE high,start Tx data transmission
- Delay(1); // while (DR!=1);
- TRX_CE=0; // Set TRX_CE low
- }
- ////////////////////////////////////////////////////
- void SetTxMode(void)
- {
- TRX_CE=0;
- TXEN=1;
- Delay(1); // delay for mode change(>=650us)
- }
- void main(void)
- {
- uchar i;
- nRF905Init();
- Config905();
- while(1)
- {
- if(KEY0==0) //有鍵按下
- {
- Delay(20);
- if(KEY0 == 0)
- {
- while(!KEY0); //等待按鍵松開(kāi) RED
- SUM++;
- if(SUM == 5) SUM = 1;
- if(SUM == 1)
- {
- TxRxBuf[0]=0x11;
- for(i=0;i<2;i++)
- {
- SetTxMode();// Set nRF905 in Tx mode
- TxPacket(TxRxBuf);// Send data by nRF905
- }
- }
- else if(SUM == 2)
- {
- TxRxBuf[0]=0x12;
- for(i=0;i<2;i++)
- {
- SetTxMode();// Set nRF905 in Tx mode
- TxPacket(TxRxBuf);// Send data by nRF905
- }
- }
- else if(SUM == 3)
- {
- TxRxBuf[0]=0x13;
- for(i=0;i<2;i++)
- {
- SetTxMode();// Set nRF905 in Tx mode
- TxPacket(TxRxBuf);// Send data by nRF905
- }
- }
- else if(SUM == 4)
- {
- TxRxBuf[0]=0x14;
- for(i=0;i<2;i++)
- {
- SetTxMode();// Set nRF905 in Tx mode
- TxPacket(TxRxBuf);// Send data by nRF905
- }
- }
- }
- }
- }
- }
- 4,接受信號(hào)整機(jī)程序
- #include <regx52.h>
- #define uchar unsigned char
- #define uint unsigned int
- /*------------LCD12864相關(guān)聲明-----------------------------*/
- #define com_byte 0
- #define dat_byte 1
- sbit cs =P0^0;
- sbit sid=P0^1;
- sbit sck=P0^2;
- uchar lcdPosX, lcdPosY; //X,Y坐標(biāo)
- uchar halfScr, halfLineCnt, basicBlock; //半屏,半屏行數(shù),N*8塊
- uchar code TAB1[]={"20 年 月 上行"};//第一行初始化.
- uchar code TAB2[]={" : : ℃"};
- uchar code TAB3[]={"0123456789: "};
- /**************************************************************/
- //===============================================
- void delay_Ms (uchar ms)
- {
- uchar i;
- while (--ms)
- {
- for (i = 0; i < 125; i++);
- }
- }
- /**************************************************************
- 函數(shù)名稱:void w_12864byte(uchar byte)
- 函數(shù)功能: 寫(xiě)字節(jié)
- **************************************************************/
- void w_12864byte(uchar byte)
- {
- uchar i;
- for(i=0;i<8;i++)
- {
- sck=0;
- byte<<=1;
- sid=CY;
- sck=1;
- }
- }
- /**************************************************************
- 函數(shù)名稱:uchar r_12864byte(void)
- 函數(shù)功能: 讀字節(jié)
- ***************************************************************/
- uchar r_12864byte(void)
- {
- uchar i,temp1,temp2;
- temp1 = 0;
- temp2 = 0;
- for(i=0;i<8;i++)
- {
- temp1=temp1<<1;
- sck = 0;
- sck = 1;
- sck = 0;
- if(sid) temp1++;
- }
- for(i=0;i<8;i++)
- {
- temp2=temp2<<1;
- sck = 0;
- sck = 1;
- sck = 0;
- if(sid) temp2++;
- }
- return ((0xf0&temp1)+(0x0f&temp2));
- }
- /**************************************************************
- 函數(shù)名稱:void c_12864busy( void )
- 函數(shù)功能: 檢測(cè)忙函數(shù)
- **************************************************************/
- void c_12864busy( void )
- {
- do
- w_12864byte(0xfc); //11111,RW(1),RS(0),0
- while(0x80&r_12864byte());
- }
- /**************************************************************
- 函數(shù)名稱:void w_12864(bit dat_byte_com_byte,uchar byt)
- 函數(shù)功能: 寫(xiě)入函數(shù)
- ***************************************************************/
- void w_12864(bit dat_byte_com_byte,uchar byt)
- {
- uchar temp;
- if(dat_byte_com_byte==0) //為零,寫(xiě)入指令
- temp=0xf8; //11111,RS(0),RW(0),0
- else //否則,寫(xiě)入數(shù)據(jù)
- temp=0xfa; //11111,RS(1),RW(0),0
- cs=1;
- c_12864busy();
- w_12864byte(temp);
- w_12864byte(byt&0xf0); //寫(xiě)入高四位
- w_12864byte(byt<<4); //寫(xiě)入低四位
- cs=0;
- }
- void lcdClear (void)
- {
- w_12864(com_byte,0x01);
- }
- void wrPosition (void)
- {
- w_12864(com_byte,0x34);
- w_12864(com_byte,lcdPosY);
- w_12864(com_byte,lcdPosX);
- w_12864(com_byte,0x30);
- }
- //===============================================
- void displayPhoto (uchar *bmp, uchar bmpCls)
- {
- lcdPosX = 0x80;
- halfScr = 2;
-
- for (;halfScr != 0; halfScr--)
- {
- lcdPosY = 0x80;
- halfLineCnt = 32;
-
- for (;halfLineCnt != 0; halfLineCnt--)
- {
- basicBlock = 16;
- wrPosition ();
-
- for (; basicBlock != 0; basicBlock--)
- {
- if (bmpCls == 0)
- {
- w_12864(dat_byte, *bmp++);
- }
- else if (bmpCls == 1)
- {
- w_12864(dat_byte,0x00);
- }
- }
- lcdPosY++;
- }
- lcdPosX = 0x88;
- }
- w_12864(com_byte,0x36);
- w_12864(com_byte,0x30);
- }
- //字符反白顯示
- //輸入?yún)?shù):CX=要反白字符的行(0-3)
- //CY=要反白字符的列(0-7)
- //width=要反白字符的長(zhǎng)度(1-16)
- //===============================================
- void convertChar (uchar CX, CY, width)
- {
- displayPhoto(0,1);
- lcdPosY = 0x80;
- if (CX == 0)
- {
- CX = 0x80;
- halfLineCnt = 16;
- }
- else if (CX == 1)
- {
- CX = 0x80;
- halfLineCnt = 32;
- }
- else if (CX == 2)
- {
- CX = 0x88;
- halfLineCnt = 16;
- }
- else if (CX == 3)
- {
- CX = 0x88;
- halfLineCnt = 32;
- }
- lcdPosX = CX + CY;
-
- for (; halfLineCnt != 0; halfLineCnt--)
- {
- basicBlock = width;
- wrPosition();
-
- for (;basicBlock != 0; basicBlock--)
- {
- if (halfLineCnt > 16)
- {
- w_12864(dat_byte,0x00);
- }
- else
- {
- w_12864(dat_byte,0xff);
- }
- }
- lcdPosY++;
- }
- w_12864(com_byte,0x36);
- w_12864(com_byte,0x30);
- }
- void dispString(uchar X,uchar Y,uchar speed, uchar *msg)
- {
- if (X == 0)
- {
- X = 0x80;
- }
- else if (X == 1)
- {
- X = 0x90;
- }
- else if (X == 2)
- {
- X = 0x88;
- }
- else if (X == 3)
- {
- X = 0x98;
- }
- Y = X + Y;
- w_12864(com_byte,Y);
- while (*msg)
- {
- w_12864(dat_byte,*msg++);
- delay_Ms(speed);
- }
- }
- //=============================================================
- /**************************************************************
- 函數(shù)名稱:void init_12864(void)
- 函數(shù)功能:初始化12864
- ***************************************************************/
- void init_12864(void)
- {
- uint i;
- w_12864(com_byte,0x30); //基本指令功能.
- w_12864(com_byte,0x0c); //顯示打開(kāi),關(guān)光標(biāo),反白關(guān).
- w_12864(com_byte,0x01); //清屏指令.
- w_12864(com_byte,0x06); //AC自動(dòng)加一
- w_12864(com_byte,0x80);
- for(i=0;i<16;i++)
- w_12864(dat_byte,TAB1[i]);
- w_12864(com_byte,0x90);
- for(i=0;i<16;i++)
- w_12864(dat_byte,TAB2[i]);
- dispString(2,0,1,"歡迎乘學(xué)院路公交");
- dispString(3,0,1,"志華站=>財(cái)經(jīng)學(xué)院");
- }
- 5,時(shí)鐘程序
- #ifndef _CLOCK_H_
- #define _CLOCK_H_
- #include <regx52.h>
- //#define PortDisplayData P0 //定義數(shù)碼管數(shù)據(jù)和位選擇輸出口
- //#define PortDisplayBit P1
- unsigned char ucClockStatu; //時(shí)鐘狀態(tài)
- #define RUNING 0x00
- #define MODIFY_YEA 0x01
- #define MODIFY_MON 0x02
- #define MODIFY_DAY 0x03
- #define MODIFY_HOU 0x04
- #define MODIFY_MIN 0x05
- #define MODIFY_SEC 0x06
- //定義跟DS1302相關(guān)的數(shù)據(jù)
- sbit SCLK = P3^4; //實(shí)時(shí)時(shí)鐘端口定義
- sbit SDAT = P3^6;
- sbit SRST = P3^7;
- //定義跟鍵盤有關(guān)的端口
- sbit FUNTION_KEY = P1^6;
- sbit INCREASE_KEY = P1^7;
- sbit DECREASE_KEY = P1^5;
- sbit WENXING_KEY =P1^4;
- sbit PLAY_KEY = P1^3;
- sbit UP_DOWN__KEY = P1^2;//上下行切換鍵
- #define W_OP 0x00 //定義寫(xiě)操作
- #define R_OP 0x01 //定義讀操作
- #define SEC 0x80 //秒寄存器地址
- #define MIN 0x82 //分寄存器地址
- #define HOU 0x84 //小時(shí)寄存器地址
- #define WEK 0x8a //星期寄存器地址
- #define DAY 0x86 //日寄存器地址
- #define MON 0x88 //月寄存器地址
- #define YER 0x8c //年寄存器地址
- #define CHARGER 0x90 //充電控制寄存器地址
- //充電控制寄存器結(jié)構(gòu):TCS為控制位,當(dāng)它的值為1010時(shí)開(kāi)啟充電功能,其它值都禁止充電,芯片上電時(shí)禁止充電.
- //DS為二極管選擇位,選擇串在VCC1和VCC2之間的二極管個(gè)數(shù),當(dāng)值為01時(shí)選擇一個(gè)二極管,為10時(shí)選擇兩個(gè)二極管,其它值為禁止充電.
- //RS為電阻選擇寄存器,選擇串在VCC1和VCC2之間的電阻值,當(dāng)值為00時(shí)不選擇任何電阻,而且禁止充電,01時(shí)為2K,10時(shí)為4K,11時(shí)為8K
- //_____________________________
- //|TCS|TCS|TCS|TCS|DS|DS|RS|RS|
- //|___|___|___|___|__|__|__|__|
- #define WPR 0x8e //寫(xiě)保護(hù)寄存器地址
- #define DISABLE 0x80 //開(kāi)啟寫(xiě)保護(hù)
- #define ENABLE 0x00 //關(guān)閉寫(xiě)保護(hù)
- unsigned char OldSecond;
- unsigned char OldMinute;
- unsigned char OldHour;
- unsigned char NewSecond;
- unsigned char NewMinute;
- unsigned char NewHour;
- unsigned char TempSecond;
- unsigned char TempMinute;
- unsigned char TempHour;
- unsigned char OldDay;
- unsigned char OldMonth;
- unsigned char OldYear;
- unsigned char NewDay;
- unsigned char NewMonth;
- unsigned char NewYear;
- unsigned char TempDay;
- unsigned char TempMonth;
- unsigned char TempYear;
- unsigned int uiTimerHalfSecond;
- unsigned char ucTimerKeyChange;
- unsigned char ucTimerDelay;
- bit bFlagFlshTime;
- #endif
復(fù)制代碼
6,以上就是我做的公交車自動(dòng)報(bào)站系統(tǒng),站點(diǎn)名字可以更改 如果解決了你的問(wèn)題 請(qǐng)幫我評(píng)論 贊一個(gè) 謝謝了
0.png (15.83 KB, 下載次數(shù): 57)
下載附件
2019-8-28 19:09 上傳
全部資料51hei下載地址:
公交無(wú)線自動(dòng)報(bào)站【增加溫度顯示,增加日期,上下行功能,模擬4站】_2017.10.19.rar
(8.56 MB, 下載次數(shù): 140)
2019-8-28 10:21 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|
|