⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.lst

📁 This the code using PIC MCU to control
💻 LST
字号:
     1: 

     2: #include <pic.h>

     3: #include "pic_setting.h"

     4: #include "CC1100.h"

     5: #include "CC1100LIB.C"

     6: 

     7: BYTE paTable[] = {0xC0, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F };

     8: BYTE txBuffer[] = {2, 1,0x01};

     9: BYTE rxBuffer[2];

    10: BYTE dpybuffer[10]={0x11,0xF9,0x23,0x61,0xC9,0x45,0x05,0xF1,0x01,0x41};

    11: 

    12: //------------------------------------------------------------------

    13: void InitPIC16F72() {

    14:         TRISA=RACNF;

    15:         TRISB=RBCNF;

    16:         TRISC=RCCNF;

    17: 

    18:         ADCON1=0x06; //ADC OFF

    19:         OPTION=0x87;    

    20:         T1CON=0x31;

    21: 

    22:         PORTC=0XFF;     //数码管 OFF

    23:         LED1=0;         //LED ON

    24:         LED2=0;

    25:         

    26:         P_SCLK=0;

    27:         P_CSn=1;

    28:         P_SI=0;

    29:         Dly1mS(200);

    30: }

    31: 

    32: //--------------------------------------------------------------

    33: BYTE KeyScan(void)

    34: {

    35:         TMR0=0; T0IF=0;

    36:         OPTION=0x07;    //portb pull up

    37:         Dly1mS(2);

    38:         while(1)

    39:         {

    40:                 if(T0IF) goto   l_exit_key;

    41:                 Current_key=PORTB|0xc3;

    42:                 if(Current_key!=Old_key)

    43:                 {

    44:                 Dly1mS(20);

    45:                 Current_key=PORTB|0xc3;

    46:                 if(Current_key!=Old_key)        //key state change?

    47:                         {

    48:                         Old_key=Current_key;

    49:                         if(Old_key!=0xff)

    50:                                 {       

    51:                                 Keyflag=1;      //new key

    52:                                 goto    l_exit_key;

    53:                                 }

    54:                         else

    55:                 Keyflag=0;      //key release           

    56:                         }

    57:                 else

    58:                          Keyflag=0;             //niose 

    59:                 }

    60:                 else

    61:                         Keyflag=0;              ////key state   do not be changed

    62:         }

    63: l_exit_key:

    64:         LED2=1;

    65:         LED1=1;

    66:         OPTION=0x87;

    67:         return(Keyflag);

    68: 

    69:         

    70: }

    71: 

    72: 

    73: void TxCC1100(void);

    74: unsigned char RxCC1100(void);

    75: 

    76: //-----------------------------------------------------------

    77: void main() 

    78: {

    79:         BYTE rfstate;

    80:         InitPIC16F72();

    81:         POWER_UP_RESET_CC1100();

    82:         halRfWriteRfSettings();

    83:         halSpiWriteBurstReg(CC1100_PATABLE, paTable, sizeof(paTable));

    84:         halSpiStrobe(CC1100_SCAL);

    85:         Dly1mS(2);

    86:         while(1)

    87:         {

    88:                 rfstate=halSpiReadStatus(CC1100_MARCSTATE);

    89:                 if((rfstate& 0x1f)==0x00)

    90:                 {

    91:                         LED1=0;

    92:                         LED2=0;

    93:                         POWER_UP_RESET_CC1100();

    94:                         halRfWriteRfSettings();

    95:                         

    96:                 }

    97:                 KeyScan();

    98:                 if(Keyflag)

    99:                 {

   100:                         txBuffer[1]=0;

   101:                         if(Old_key==0xFB)

   102:                                 txBuffer[1]=1;  

   103:                         if(Old_key==0xF7)

   104:                                 txBuffer[1]=2;

   105:                         if(Old_key==0xEF)

   106:                                 txBuffer[1]=3;

   107:                         if(Old_key==0xDF)

   108:                                 txBuffer[1]=4;

   109:                         txBuffer[2]=0x01;

   110:                 TxCC1100();

   111:                 }

   112:                 else

   113:                 {       

   114:                         if(RxCC1100())

   115:                         {

   116:                                 if(rxBuffer[1]==0x01) 

   117:                                 {

   118:                 

   119:                                         txBuffer[2]=0x07;

   120:                                         txBuffer[1]=rxBuffer[0];

   121:                                         halSpiStrobe(CC1100_SIDLE);

   122:                                         Dly1mS(500);

   123:                                         TxCC1100();     

   124:                                 }

   125:                                 else

   126:                                         if(rxBuffer[1]==0x07) Dly1mS(500);

   127:                                         

   128:                         }               

   129:                 }

   130:          }

   131: }

   132: 

   133: //-------------------------------------------------------------

   134: void TxCC1100()

   135: {

   136:         unsigned char   i;

   137: //      halSpiWriteReg(0x3E,0xC0);      

   138:         halSpiWriteReg(CC1100_FREND0, 0x10);//POWER=10DBM

   139:         Dly1mS(50);     

   140:         for(i=0;i<4;i++)

   141:         {       

   142:         halRfSendPacket(txBuffer, sizeof(txBuffer));

   143:                 Dly1mS(50);

   144:         }

   145: //      halSpiWriteReg(0x3E,0x7f);      //POWER=0DBM

   146:         halSpiWriteReg(CC1100_FREND0, 0x11);

   147:         Dly1mS(50);

   148:         halRfSendPacket(txBuffer, sizeof(txBuffer));

   149: 

   150:         Dly1mS(100);

   151:         PORTC=0xFF;     

   152: }

   153: 

   154: //-----------------------------------------------------------

   155: unsigned char RxCC1100(void)

   156: {       

   157:         unsigned char   length,i;

   158:         length = sizeof(rxBuffer);

   159:     if (halRfReceivePacket(rxBuffer, length))

   160:                 {

   161:                         i=rxBuffer[0];  

   162:                         PORTC=dpybuffer[i];

   163:                         LED2=0;

   164:                         LED1=1;

   165:                         return 1;

   166:                         

   167:                 }

   168:         else    return 0;

   169:         

   170: }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -