|
![](static/image/common/ico_lz.png)
楼主 |
发表于 2012-5-12 22:59:09
|
显示全部楼层
接收是用stc12c5608ad的
部分程序在这里
#include ".\\nRF24L01\\nRF24L01.h"
#include "def.h"
#include <STC12C56.H>
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
#define PWM_OUT_IO P2
uchar i=0;
uchar flag=1;
uchar code PWM_OUT[8] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}; //通道号
uchar PWM_VALUE[8] = {0, 0, 0, 0, 0,0, 0, 0}; //根据需要刷新数据
uchar TX_PWM_VALUE[10] = {0, 1, 1, 0, 0, 0, 0, 0, 0, 0}; //预留反馈信息
uchar code PWM_LONG[2][256] = {
{ //高8位
0xef
},{ //低8位
0x78
}}; //通道定时值表: 长值(第1行高8位;第2行低8位)
uchar code PWM_SHORT[2][256] = {
{ //短高8位
0xd7
}, { //短低8位
0x17
}}; //通道定时值表: 短值(第1行高8位,第2行低8位)
void Delay(uchar s)
{
uchar i,j;
for(i=0; i<s; i++)
{
for(j=0; j<148; j++) ;
}
}
void timer_init()
{
IP |= 0X02;
IPH |= 0X02; //设置PT0,PT0H = 1 定时器0中断优先级最高
TMOD = 0X01; //16位定时器
AUXR|=0X80; //1T定时模式
TH0 = (65536-50000)/256; //初始延时50ms
TL0 = (65536-50000)%256;
EA = 1; //开总中断
ET0 = 1; //开定时器0中断
TR0 = 1; //启动定时器0
///////////////////////这里测试状态//////////////////
}
void time0() interrupt 1 //using 2
{
if(flag==0) //短时重装值
{
TH0 = PWM_SHORT[0][PWM_VALUE[i]];
TL0 = PWM_SHORT[1][PWM_VALUE[i]];
PWM_OUT_IO = 0X00; //关闭所有通道
flag = 1;
i++;
if(i==8) //通道位计数
{
i = 0;
}
}
else //长时500uS以上重装值
{
TH0 = PWM_LONG[0][PWM_VALUE[i]];
TL0 = PWM_LONG[1][PWM_VALUE[i]];
PWM_OUT_IO = PWM_OUT[i]; //单独通道位输出
flag = 0;
//i++;
if(i==8) //通道位计数
{
i = 0;
}
}
}
/***********************************/
void main()
{
PWM_OUT_IO = 0x00;
timer_init();
init_io(); //初始化NRF24L01接口
//使用IO口模拟SPI方式通讯
Delay(255);
nRF24L01_TxPacket(TX_PWM_VALUE);
while(1)
{
Delay(200);
SetRX_Mode();
nRF24L01_RxPacket( PWM_VALUE );
}
} |
|