/***********************************************************************
** Device: A7129
** File: main.c
** Target: Winbond W77LE58
** Tools: ICE
** Updated: 2025-06-30
** Description:
** This file is a sample code for your reference.
**
** Copyright (C) 2025 AMICCOM Corp.
**
*********************************************************************/
#include "define.h"
#include "w77le58.h"
#include "a7129reg.h"
#include "a7129config.h"
#include "Uti.h"
/*********************************************************************
** I/O Declaration
*********************************************************************/
#define SCS P1_0 //SPI SCS
#define SCK P1_1 //SPI SCK
#define SDIO P1_2 //SPI SDIO
#define CKO P1_3 //CKO
#define GIO1 P1_4 //GIO1
#define GIO2 P1_5 //GIO2
/*********************************************************************
** Constant Declaration
*********************************************************************/
#define TIMEOUT 100 //100ms
#define t0hrel 1000 //1ms
/*********************************************************************
** Global Variable Declaration
*********************************************************************/
Uint8 data timer;
Uint8 data TimeoutFlag;
Uint16 idata RxCnt;
Uint32 idata Err_ByteCnt;
Uint32 idata Err_BitCnt;
Uint16 idata TimerCnt0;
Uint8 data *Uartptr;
Uint8 data UartSendCnt;
Uint8 data CmdBuf[11];
Uint8 idata tmpbuf[64];
const Uint8 code BitCount_Tab[16]={0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4};
const Uint8 code ID_Tab[8]={0x34,0x75,0xC5,0x8C,0xC7,0x33,0x45,0xE7}; //ID code
const Uint8 code PN9_Tab[]=
{ 0xFF,0x83,0xDF,0x17,0x32,0x09,0x4E,0xD1,
0xE7,0xCD,0x8A,0x91,0xC6,0xD5,0xC4,0xC4,
0x40,0x21,0x18,0x4E,0x55,0x86,0xF4,0xDC,
0x8A,0x15,0xA7,0xEC,0x92,0xDF,0x93,0x53,
0x30,0x18,0xCA,0x34,0xBF,0xA2,0xC7,0x59,
0x67,0x8F,0xBA,0x0D,0x6D,0xD8,0x2D,0x7D,
0x54,0x0A,0x57,0x97,0x70,0x39,0xD2,0x7A,
0xEA,0x24,0x33,0x85,0xED,0x9A,0x1D,0xE0
}; // This table are 64bytes PN9 pseudo random code.
/*********************************************************************
** function Declaration
*********************************************************************/
void Timer0ISR(void);
void UART0Isr(void);
void InitTimer0(void);
void InitUART0(void);
void A7129_POR(void);
Uint8 InitRF(void);
Uint8 A7129_Config(void);
Uint8 A7129_WriteID(void);
Uint8 A7129_Cal(void);
void StrobeCMD(Uint8);
void ByteSend(Uint8);
Uint8 ByteRead(void);
void A7129_WriteReg(Uint8, Uint16);
Uint16 A7129_ReadReg(Uint8);
void A7129_WritePageA(Uint8, Uint16);
Uint16 A7129_ReadPageA(Uint8);
void A7129_WritePageB(Uint8, Uint16);
Uint16 A7129_ReadPageB(Uint8);
void A7129_WriteFIFO(void);
void RxPacket(void);
void Err_State(void);
void entry_deep_sleep_mode(void);
void wake_up_from_deep_sleep_mode(void);
/*********************************************************************
* main loop
*********************************************************************/
/*Frequency setting description.*/
//User can choose frequency in ''A7129CONFIG.h''
void main(void)
{
//initsw
PMR |= 0x01; //set DME0
//initHW
P0 = 0xFF;
P1 = 0xFF;
P2 = 0xFF;
P3 = 0xFF;
P4 = 0x0F;
InitTimer0();
InitUART0();
TR0=1; //Timer0 on
EA=1; //enable interrupt
A7129_POR(); //power on only
while(1)
{
if(InitRF()) //init RF
{
entry_deep_sleep_mode();
Delay1ms(2);
wake_up_from_deep_sleep_mode();
}
else
{
break;
}
}
/*modify Frequency.*/
//Step1.Using EK UI tool.
//Step2.Load config.(Must choose the same config as A7129CONFIG.h)
//Step3.modify the RF Frequency in Frequency Setup.
//Step4.Look at PLL1 and PLL2 register.
/*Ex:Load (433MHz 100kbps IFBW = 100KHz Fdev = 37.5KHz Crystal=12.8MHz)->modify the RF Frequency(433.301)->Look at PLL1 and PLL2 register
A7129_WriteReg(PLL1_REG, 0x0A21);
A7129_WriteReg(PLL2_REG, 0xDA05);
*/
if((P4 & 0x04)==0x04) //if P4.2=1, master
{
while(1)
{
A7129_WriteFIFO(); //write data to TX FIFO
StrobeCMD(CMD_TX);
Delay10us(1);
while(GIO2); //wait transmit completed
StrobeCMD(CMD_RX);
Delay10us(1);
timer=0;
TimeoutFlag=0;
while((GIO2==1)&&(TimeoutFlag==0)); //wait receive completed
if(TimeoutFlag)
{
StrobeCMD(CMD_STBY);
}
else
{
RxPacket();
Delay10ms(10);
}
}
}
else //if P4.2=0, slave
{
RxCnt = 0;
Err_ByteCnt = 0;
Err_BitCnt = 0;
while(1)
{
StrobeCMD(CMD_RX);
Delay10us(1);
while(GIO2); //wait receive completed
RxPacket();
A7129_WriteFIFO(); //write data to TX FIFO
StrobeCMD(CMD_TX);
Delay10us(1);
while(GIO2); //wait transmit completed
Delay10ms(9);
}
}
}
/************************************************************************
** Timer0ISR
************************************************************************/
void Timer0ISR(void) interrupt 1
{
TH0 = (65536-t0hrel)>>8; //Reload Timer0 high byte, low byte
TL0 = 65536-t0hrel;
timer++;
if(timer >= TIMEOUT)
{
TimeoutFlag=1;
}
TimerCnt0++;
if(TimerCnt0 == 500)
{
TimerCnt0=0;
CmdBuf[0]=0xF1;
memcpy(&CmdBuf[1], &RxCnt, 2);
memcpy(&CmdBuf[3], &Err_ByteCnt, 4);
memcpy(&CmdBuf[7], &Err_BitCnt, 4);
UartSendCnt=11;
Uartptr=&CmdBuf[0];
SBUF=CmdBuf[0];
}
}
/************************************************************************
** UART0ISR
************************************************************************/
void UART0Isr(void) interrupt 4 using 3
{
if(TI==1)
{
TI=0;
UartSendCnt--;
if(UartSendCnt !=0)
{
Uartptr++;
SBUF = *Uartptr;
}
}
}
/************************************************************************
** init Timer0
************************************************************************/
void InitTimer0(void)
{
TR0 = 0;
TMOD=(TMOD & 0xF0)|0x01; //Timer0 mode=1
TH0 = (65536-t0hrel)>>8; //setup Timer0 high byte, low byte
TL0 = 65536-t0hrel;
TF0 = 0; //Clear any pending Timer0 interrupts
ET0 = 1; //Enable Timer0 interrupt
}
/************************************************************************
** Init UART0
************************************************************************/
void InitUART0(void)
{
TH1 = 0xFD; //BaudRate 9600;
TL1 = 0xFD;
SCON= 0x40;
TMOD= (TMOD & 0x0F) | 0x20;
REN = 1;
TR1 = 1;
ES = 1;
}
/*********************************************************************
** Strobe Command
*********************************************************************/
void StrobeCMD(Uint8 cmd)
{
Uint8 i;
SCS=0;
for(i=0; i<8; i++)
{
if(cmd & 0x80)
SDIO = 1;
else
SDIO = 0;
_nop_();
SCK=1;
_nop_();
SCK=0;
cmd<<=1;
}
SCS=1;
}
/************************************************************************
** ByteSend
************************************************************************/
没有合适的资源?快使用搜索试试~ 我知道了~
A7129 433MHZ,代码

共7个文件
h:5个
c:2个

需积分: 0 0 下载量 61 浏览量
2025-08-28
11:13:01
上传
评论
收藏 9KB ZIP 举报
温馨提示
A7129 433MHZ,RF代码
资源推荐
资源详情
资源评论






























收起资源包目录









共 7 条
- 1
资源评论


gxyou
- 粉丝: 1
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 预应力高强混凝土管桩施工技术.doc
- 基于大数据的农膜品牌营销分析-洞察阐释.pptx
- 基于PLC的XA卧式铣床电气控制系统设计.doc
- 浙江中小企业发展电子商务的现状及对策分析.doc
- 最完整竣工结算资料.docx
- 北京小区地板采暖施工组织设计.doc
- 福建省西北某村人饮工程可行性研究报告p.doc
- 电压-电流法测定电线电缆绝缘电阻的不确定度评定.doc
- 给排水工程量计算规则.doc
- 探讨企业项目管理的薪酬激励问题.docx
- 试析视觉表现的网络广告设计.docx
- 第八章矢量算法与场论初步张量算法与黎曼几何初步SECTION2.doc
- 年度晋级考核制度.doc
- PLC变频恒压供水控制系统设计方案.doc
- 180°翻转机主动减速电机选型.doc
- 著名综合大楼给排水施工方案(创鲁班奖).doc
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制
