MCU:PIC16F1829
无线发射模块:VER001
无线接收模块:RCT7615
硬件原理图:
硬件连接说明:
序号 | 寄存器配置值 | 频点 | 发送器拨码 | 接收器拨码(2\3\4) | 备注 |
1 | 0x02906 | 5740 | 2 | 000 | |
2 | 0x02910 | 5760 | 3 | 001 | |
3 | 0x0291a | 5780 | 4 | 010 | |
4 | 0x02984 | 5800 | 5 | 011 | |
5 | 0x0298e | 5820 | 6 | 100 | |
6 | 0x02998 | 5840 | 7 | 101 | |
7 | 0x02a02 | 5860 | 8 | 110 | |
8 | 0x02a0c | 5880 | 9 | 111 |
程序源代码:
#include <pic.h>
#include <pic16f1829.h>
#include "Mydefine.h"
#include "Ram.h"
#define _XTAL_FREQ 8000000 //用于精确延时 8M
//#define _XTAL_FREQ 32000000 //用于精确延时 32M
//配置为内部8MHZ的RC时钟源,看门狗关闭,上电复位使能,MCLR引脚为复位引脚,欠压复位开启,读保护
//如果RC=8MHZ _PLLEN_ON
__CONFIG(FCMEN_ON&FOSC_INTOSC&IESO_OFF&CLKOUTEN_OFF&BOREN_ON&CPD_ON&CP_ON&MCLRE_OFF&WDTE_OFF);
//__CONFIG(LVP_OFF&BORV_19&STVREN_ON&PLLEN_ON&WRT_OFF);//32M
__CONFIG(LVP_OFF&BORV_19&STVREN_ON&PLLEN_OFF&WRT_OFF);//8M
void init()
{
//OSCCON = 0xf0; //f0内部时钟源32MHz 4xPLL
OSCCON=0X72; //内部时钟源8MHz 禁止4xPLL
OPTION_REG=0x03; //预分频为1:16,内部时钟
ANSELB=0x00; //
ANSELA=0x00;
//TRISB = 0x07;//RB3,2,4
TRISA = 0x38;//RA3\4\5拨码输入
}
void myspi1(uint8 add , uint32 data)
{
SPILE = 0;
for(Q=0;Q <= 4;Q++)
{
SDO = 0;
if(add&0x01)SDO=1;
__delay_us(1);
SCK = 1;
__delay_us(1);
SCK = 0;
add >>= 1;
}
for(Q=0;Q <= 19;Q++)
{
SDO = 0;
if(data&0x01)SDO=1;
__delay_us(1);
SCK = 1;
__delay_us(1);
SCK = 0;
data >>= 1;
}
SPILE = 1;
__delay_us(2);
SPILE = 0;
}
void main()
{
init();
__delay_ms(1000);
lstatus = PORTA;
lstatus &= 0x38;
while(1)
{
switch(lstatus)
{
case 0x00:
ADD = 0x08;
DATA = 0x000000;
myspi1(ADD , DATA);
ADD = 0x11;
DATA = 0x02906;
myspi1(ADD , DATA);
break;
case 0x08:
ADD = 0x08;
DATA = 0x000000;
myspi1(ADD , DATA);
ADD = 0x11;
DATA = 0x02910;
myspi1(ADD , DATA);
break;
case 0x10:
ADD = 0x08;
DATA = 0x000000;
myspi1(ADD , DATA);
ADD = 0x11;
DATA = 0x0291a;
myspi1(ADD , DATA);
break;
case 0x18:
ADD = 0x08;
DATA = 0x000000;
myspi1(ADD , DATA);
ADD = 0x11;
DATA = 0x02984;
myspi1(ADD , DATA);
break;
case 0x20:
ADD = 0x08;
DATA = 0x000000;
myspi1(ADD , DATA);
ADD = 0x11;
DATA = 0x0298e;
myspi1(ADD , DATA);
break;
case 0x28:
ADD = 0x08;
DATA = 0x000000;
myspi1(ADD , DATA);
ADD = 0x11;
DATA = 0x02998;
myspi1(ADD , DATA);
break;
case 0x30:
ADD = 0x08;
DATA = 0x000000;
myspi1(ADD , DATA);
ADD = 0x11;
DATA = 0x02a02;
myspi1(ADD , DATA);
break;
case 0x38:
ADD = 0x08;
DATA = 0x000000;
myspi1(ADD , DATA);
ADD = 0x11;
DATA = 0x02a0c;
myspi1(ADD , DATA);
break;
default:break;
}//END switch(lstatus)
while(1)
{
status = PORTA;
status &= 0x38;
if(lstatus != status)
{
lstatus = status;
break;
}//END if(lstatus != status)
__delay_ms(500);
}//END while(1)
}//END while(1)
}//END main()
void interrupt pic(void) //接收中断处理
{
;
}