//ICC-AVR application builder : 2007-8-11 20:37:32
// Target : M16
// Crystal: 8.0000Mhz
#include <iom16v.h>
#include <macros.h>
#define uint unsigned int
#define uchar unsigned char
//---------------------------------模式控制定义---------------------------------
//#define nrf905_TX_EN PB0 //输出1
#define Hign_nrf905_TX_EN PORTB |= (1 << PB0);
#define Low_nrf905_TX_EN PORTB &= ~(1 << PB0);
//#define nrf905_TRX_CE PD5 //输出1
#define Hign_nrf905_TRX_CE PORTD |= (1 << PD5);
#define Low_nrf905_TRX_CE PORTD &= ~(1 << PD5);
//#define nrf905_PWR PB1 //输出1
#define Hign_nrf905_PWR PORTB |= (1 << PB1);
#define Low_nrf905_PWR PORTB &= ~(1 << PB1);
//--------------------------------NRF905-SPI口接口定义--------------------------
//#define nrf905_MISO PB6 //输入0
//#define nrf905_MOSI PB5 //输出1
//#define nrf905_SCK PB7 //输出1
#define Low_nrf905_SCK PORTB &= ~(1 << PB7);
//#define nrf905_CSN PB4 //输出1
#define Hign_nrf905_CSN PORTB |= (1 << PB4);
#define Low_nrf905_CSN PORTB &= ~(1 << PB4);
//-------------------------------NRF905状态输出口-------------------------------
//#define nrf905_CD PD4 //输入0
#define Hign_nrf905_CD PORTD |= (1 << PD4);
#define Low_nrf905_CD PORTD &= ~(1 << PD4);
#define Read_nrf905_CD PINB & (1 << PD4);
//#define nrf905_AM PB3 //输入0
#define Hign_nrf905_AM PORTB |= (1 << PB3);
#define Low_nrf905_AM PORTB &= ~(1 << PB3);
#define Read_nrf905_AM PINB & (1 << PB3);
//#define nrf905_DR PB2 //输入0
#define Hign_nrf905_DR PORTB |= (1 << PB2);
#define Low_nrf905_DR PORTB &= ~(1 << PB2);
#define Read_nrf905_DR PINB & (1 << PB2);
//------------------------------LCD状态输出口-----------------------------------
//#define LCD_CS PC7 //1-out
//#define Out_LCD_CS DDRC |= (1 << PC7);
#define Hign_LCD_CS PORTC |= (1 << PC7);
#define Low_LCD_CS PORTC &= ~(1 << PC7);
//#define LCD_RESET PC6 //1-out
//#define Out_CD_RESET DDRC |= (1 << PC6);
#define Hign_LCD_RESET PORTC |= (1 << PC6);
#define Low_LCD_RESET PORTC &= ~(1 << PC6);
//#define LCD_RS PC5 //1-out
//#define Out_LCD_RS DDRC |= (1 << PC5);
#define Hign_LCD_RS PORTC |= (1 << PC5);
#define Low_LCD_RS PORTC &= ~(1 << PC5);
//#define LCD_SCL PC4 //1-out
//#define Out_LCD_SCL DDRC |= (1 << PC4);
#define Hign_LCD_SCL PORTC |= (1 << PC4);
#define Low_LCD_SCL PORTC &= ~(1 << PC4);
//#define LCD_SI PC3 //1-ou
//#define Out_LCD_SI DDRC |= (1 << PC3);
#define Hign_LCD_SI PORTC |= (1 << PC3);
#define Low_LCD_SI PORTC &= ~(1 << PC3);
//-------------------------------BELL蜂明器-------------------------------------
#define Hign_BELL PORTD |= (1 << PD6);
#define Low_BELL PORTD &= ~(1 << PD6);
//-------------------------------JDQ继电器--------------------------------------
#define Hign_JDQ PORTD |= (1 << PD7)
#define Low_JDQ PORTD &= ~(1 << PD7)
//------------------------LCD字库---------------------------------------------
const uchar ling16[16]=
{0x00,0xE0,0xF0,0x08,0x08,0x18,0xF0,0xC0,0x00,0x0F,0x1F,0x20,0x20,0x30,0x1F,0x07};//0
const uchar yi16[16]=
{0x00,0x00,0x10,0xF0,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x3F,0x20,0x20,0x00};//1
const uchar er16[16]=
{0x00,0x70,0x78,0x08,0x08,0x98,0xF8,0x70,0x00,0x30,0x38,0x34,0x32,0x31,0x30,0x38};//2
const uchar san16[16]=
{0x00,0x30,0x38,0x88,0x88,0xF8,0x70,0x00,0x00,0x18,0x38,0x21,0x21,0x33,0x1E,0x0C};//3
const uchar si16[16]=
{0x00,0x00,0x80,0x60,0x30,0xF8,0xF8,0x00,0x00,0x06,0x05,0x24,0x24,0x3F,0x3F,0x24};//4
const uchar wu16[16]=
{0x00,0xF0,0xF8,0x88,0x88,0x88,0x08,0x00,0x00,0x19,0x39,0x20,0x20,0x31,0x1F,0x06};//5
const uchar liu16[16]=
{0x00,0xE0,0xF0,0x88,0x88,0x98,0x98,0x00,0x00,0x0F,0x3F,0x20,0x20,0x20,0x1F,0x0E};//6
const uchar qi16[16]=
{0x00,0x38,0x18,0x08,0x88,0xE8,0x38,0x08,0x00,0x00,0x00,0x3E,0x3F,0x00,0x00,0x00};//7
const uchar ba16[16]=
{0x00,0x70,0xF8,0x8C,0x8C,0x8C,0xF8,0x70,0x00,0x0E,0x1F,0x31,0x31,0x33,0x1F,0x0E};//8
const uchar jiu16[16]=
{0x00,0xF0,0xF8,0x08,0x08,0x18,0xF8,0xF0,0x00,0x19,0x33,0x32,0x32,0x3B,0x1F,0x0F};//9
const uchar xsdian[16]=
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x30,0x00};//.
//-------------------------------------------------------------------------------
const uchar wu[32]= //无
{0x00,0x40,0x42,0x42,0x42,0x42,0xFE,0x42,0xC2,0x42,0x43,0x42,0x60,0x40,0x00,0x00,
0x00,0x80,0x40,0x20,0x18,0x06,0x01,0x00,0x3F,0x40,0x40,0x40,0x40,0x40,0x70,0x00};
const uchar xian[32]= //线
{0x00,0x20,0x30,0xAC,0x63,0x20,0x30,0x20,0x20,0xFF,0x90,0x92,0x94,0xD0,0x80,0x00,
0x20,0x62,0x23,0x12,0x12,0x12,0x41,0x41,0x21,0x17,0x18,0x24,0x42,0x80,0xE0,0x00};
const uchar yao[32]= //遥
{0x40,0x42,0x44,0xCC,0x00,0x42,0x36,0x2A,0x22,0xFE,0x21,0x29,0x25,0x80,0x00,0x00,
0x00,0x40,0x20,0x1F,0x21,0x41,0x5D,0x49,0x49,0x4F,0x49,0x49,0x5D,0x61,0x21,0x00};
const uchar kong[32]= //控
{0x10,0x10,0x10,0xFF,0x90,0x50,0x0C,0x44,0x24,0x15,0x06,0x14,0x24,0x54,0x0C,0x00,
0x02,0x42,0x81,0x7F,0x00,0x40,0x42,0x42,0x42,0x42,0x7E,0x42,0x43,0x62,0x40,0x00};
const uchar xi[32]= //系
{0x00,0x02,0x22,0x22,0x32,0x2E,0xA2,0x62,0x22,0x22,0x91,0x09,0x01,0x00,0x00,0x00,
0x00,0x00,0x42,0x22,0x1A,0x43,0x82,0x7E,0x02,0x02,0x0A,0x13,0x66,0x00,0x00,0x00};
const uchar tong[32]= //统
{0x20,0x30,0xAC,0x63,0x30,0x88,0xC8,0xA8,0x99,0x8E,0x88,0xA8,0xCC,0x88,0x00,0x00,
0x22,0x67,0x22,0x12,0x92,0x40,0x30,0x0F,0x00,0x00,0x3F,0x40,0x40,0x41,0x70,0x00};
const uchar ji[32]= //继 //继
{0x20,0x30,0xAC,0x63,0x30,0x00,0xFE,0x88,0x90,0xA0,0xFF,0xA0,0x90,0x98,0x00,0x00,
0x22,0x67,0x22,0x12,0x12,0x00,0x7F,0x48,0x44,0x42,0x7F,0x42,0x44,0x6C,0x40,0x00};
const uchar dian[32]= //电
{0x00,0xF8,0x48,0x48,0x48,0x48,0xFF,0x48,0x48,0x48,0x48,0xFC,0x08,0x00,0x00,0x00,
0x00,0x07,0x02,0x02,0x02,0x02,0x3F,0x42,0x42,0x42,0x42,0x47,0x40,0x70,0x00,0x00};
const uchar qi[32]= //器
{0x80,0x80,0x9F,0x91,0x91,0x91,0x9F,0xE0,0x9F,0x91,0xB1,0xD1,0x9F,0xC0,0x80,0x00,
0x08,0x08,0xFC,0x8C,0x8A,0x8A,0xF9,0x00,0xF9,0x8A,0x8A,0x8C,0xFC,0x08,0x08,0x00};
const uchar kai[32]= //开
{0x80,0x82,0x82,0x82,0xFE,0x82,0x82,0x82,0x82,0x82,0xFE,0x82,0x83,0xC2,0x80,0x00,
0x00,0x80,0x40,0x30,0x0F,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00};
const uchar feng[32]= //蜂
{0x00,0xF0,0x10,0xFF,0x10,0xF8,0x90,0x88,0x4F,0x54,0xA4,0x54,0x4C,0xC4,0x40,0x00,
0x20,0x67,0x22,0x1F,0x12,0x3B,0x00,0x14,0x15,0x15,0xFF,0x15,0x15,0x14,0x00,0x00};
const uchar ming[32]= //明
{0x00,0xFC,0x44,0x44,0x44,0xFE,0x04,0x00,0xFE,0x22,0x22,0x22,0x22,0xFF,0x02,0x00,
0x00,0x0F,0x04,0x04,0x04,0x8F,0x40,0x30,0x0F,0x02,0x02,0x42,0x82,0x7F,0x00,0x00};
const uchar xiang[32]= //响
{0x00,0xFC,0x04,0x04,0xFE,0x04,0xF8,0x08,0xCC,0x4A,0x49,0xC8,0x08,0xFC,0x08,0x00,
0x00,0x1F,0x08,0x08,0x1F,0x00,0xFF,0x00,0x0F,0x08,0x08,0x4F,0x80,0x7F,0x00,0x00};
//----------------------------------NRF905-SPI指令------------------------------
#define WC 0x00
#define RRC 0x10
#define WTP 0x20
#define RTP 0x21
#define WTA 0x22
#define RTA 0x23
#define RRP 0x24
//---------------------------------发送数据-------------------------------------
uchar TxRxBuffer[4];
//----------------------------------接收地址------------------------------------
uchar TxAddress[4]={0xcc,0xcc,0xcc,0xcc };
//------------------------------------------------------------------------------
uchar count1 ,count2;
//----------------------------------寄存器配置----------------------------------
uchar RFConf[11]=
{
0x00,