📄 main.c
字号:
//ICC-AVR application builder : 2006-4-4 11:28:26
// Target : M16 PTR8000模块简单测试
// Crystal: 4MHz(11.059Mhz)
//最关键的是SPI的初始化,MSB首位和极性方式00,极性方式错误,数据则不正确
#include "confg.h"
#define MASTER //编译控制是主机还是从机
void SystemIni(void);
void port_init1(void)
{
PORTB = 0xFe;
DDRB = 0x00;
PORTC = 0x00; //m103 output only
DDRC = 0x00;
PORTD = 0xFF;
DDRD = 0x00;
}
void port_init2(void)
{
PORTB = 0xD7;
DDRB = 0x2C;
PORTC = 0x00; //m103 output only
DDRC = 0x00;
PORTD = 0x1f;
DDRD = 0xe0;
}
//SPI initialize
void spi_init(void)
{uchar temp;
//SPCR = 0xD1; //SPI中断允许,SPI允许,主机模式,MSB,极性方式00,1/16系统时钟速率
SPCR = 0x51; //不使用SPI中断,其它同上
SPSR = 0x00; //setup SPI
temp = SPSR; //!!!
temp = SPDR; //清空SPI,和中断标志,使SPI空闲
}
//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init1();
spi_init();
uart_init();
MCUCR = 0x0c;
GICR|= 0x80;//enable INT1 interrupt
GIFR = 0xc0;// 清除INT0、INT1 中断标志位
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
void init_devices2(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init2();
spi_init();
//uart_init();
//MCUCR = 0x00;
//GICR = 0x00;
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
void port_init3(void)
{
PORTB = 0x00;
DDRB = 0x00;
//PORTB = 0xD7;
// DDRB = 0x2C;
PORTC = 0x00; //m103 output only
DDRC = 0x00;
PORTD = 0x00;
DDRD = 0x20;
}
void main(void)
{
uchar *string;
int i;
init_devices();
SystemIni();
puts_hh("test start!");
init_devices2();
/*
// spi_init();
port_init3();
//nrf905_Init();
nrf905_Off();//断开电源
ACSR=0x80; //别忘了关掉模拟比较器的电源哦
MCUCR=(0<<SM2)|(1<<SM1)|(1<<SM0);//0 1 1 省电模式
MCUCR|=(1<<SE);//仅在SLEEP 指令的前一条指令置位SE
while(1){
asm( "sleep" );}
//*/
//*
while(1) {
delay_10ms(150);
init_devices();
ad_convert();//开始AD转换
init_devices2();
Read_nrf905Add();//读取nrf905的接受和发送地址
nrf905_Init();
RfSendProc();//发送数据
printf("slave add is %d\r\n",Tx_Buf[0]);
printf("command is %x\r\n",Tx_Buf[1]);
i=Tx_Buf[2]+(Tx_Buf[3]<<8);
printf("temperlature is %d\r\n",i);
i=Tx_Buf[4]+(Tx_Buf[5]<<8);
printf("vcc is %d\r\n",i);
}
//*/
}
void SystemIni()
{
delay_10ms(20);
}
/*
#pragma interrupt_handler int1_isr:3
void int1_isr(void)
{
int m;
uchar ss[2];
// delay_10ms(20);
// puts_hh("int1");
RfRecvProc();//接收处理
for(m=0;m<32;m++)
{
sprintf(ss,"%c",Rx_Buf[m]);
putss(ss);//向串口打印接收到的内容
}
putch(0x0a);
putch(0x0d);
CLR(PORTB,AM);
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -