![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
Knight_FlyCn
Joined: 10 May 2013 Posts: 16 Location: Việt Nam
|
Error with 18F4620: Expecting a structure/union |
Posted: Fri May 10, 2013 11:00 am |
|
|
Code: | /* _CPUDIV_OSC1_PLL2_1L, // Divide clock by 2
_FOSC_HS_1H, // Select High Speed (HS) oscillator
_WDT_OFF_2H, // Watchdog Timer off
MCLRE_ON_3H // Master Clear on
*/
#include <RFD.h>
#include "def_18f4620.c"
#include "slave_1_tx_rx.h"
// Xac dinh ----
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#define SPI_MODE_0 (SPI_L_TO_H | SPI_XMIT_L_TO_H)
// Them vao
#ifndef FREQ
#define FREQ 4000000
#ifndef baud
#define baud 96000
#define spbrg_value (((FREQ/64)/baud)-1)
//
#bit CS = 0xF80.4
#bit RST = 0xF82.2
#bit INT_ = 0xF81.0
#bit WAKE = 0xF82.1
#bit CS_Direction = 0xF92.4
#bit RST_Direction = 0xF94.2
#bit INT_Direction = 0xF93.0
#bit WAKE_Direction = 0xF94.1
///////////////////////////////////////////////////////////////////////////////
// Command: 0x00: IP request //
// 0x01: I_AM_LM35 //
// 0x02: I_AM_PIR
INT TEMP;
int adress;
INT VALUE;
INT16 k=0;
const int IP_request=0x00,adress_surport=0x01,ip_surport=0x10;
int I_AM_LM35=0x01;
INT DATA_SEND=0X02;
INT COMMAND;//
INT1 IP_REQUEST_FLAG=FALSE;
SHORT SLEEP_MODE=true;
//!#INT_RTCC
//!VOID NGAT_TIMER0()
//!{ printf("ngat timer0!");
//! ++;
//! IF (k>= 1000)
//! {
//! k=0;
//! SLEEP_MODE=FALSE;
//! }
//! TMR0IF=0;
//! disable_interrupts(INT_TIMER0);
//!}
//!
#INT_EXT
void ngat_RB0()
{
temp = read_ZIGBEE_short(INTSTAT); // Read and flush register INTSTAT
if ((temp&(1<<3))==(1<<3))
{
read_RX_FIFO();
COMMAND =DATA_RX[0];
SWITCH (COMMAND)
{
CASE ip_surport:
ADRESS=DATA_RX[1];
rfd_ADDRESS_short[1]=adress;
IP_REQUEST_FLAG=TRUE;
BREAK;
break;
}
}
}
void main()
{
TRISB1=TRISB2=TRISB3=1;
TRISC0=TRISD3=0;
CS_Direction = 0; // Set direction to be output
RST_Direction = 0; // Set direction to be output
INT_Direction = 1; // Set direction to be input
WAKE_Direction = 0; // Set direction to be output
Delay_ms(5);
setup_spi(SPI_MASTER | SPI_MODE_0 | SPI_CLK_DIV_4); // Initialize SPI module
pin_reset(); // Activate reset from pin
software_reset(); // Activate software reset
RF_reset(); // RF reset
set_WAKE_from_pin(); // Set wake from pin
set_long_address(ADDRESS_long_1);
set_short_address(rfd_ADDRESS_short); // Set short address
set_PAN_ID(PAN_ID); // Set PAN_ID
init_ZIGBEE_nonbeacon(); // Initialize ZigBee module
nonbeacon_device();
set_TX_power(31); // Set max TX power
set_frame_format_filter(1); // 1 all frames, 3 data frame only
set_reception_mode(1); // 1 normal mode
enable_int();
pin_wake(); // Wake from pin
//enable interrupt ext
enable_interrupts(GLOBAL);
enable_interrupts(INT_EXT);
ext_int_edge(H_to_L);
// gioi thieu
printf("****************************************\r\n");
Printf(" ");
Printf(" RFD_designed by Huynh Thanh Dien\r\n");
Printf(" ");
printf("****************************************\r\n");
// IP request
printf(" Requesting IP...\r\n");
PAN_ID_destination[0] = PAN_ID[0];
PAN_ID_destination[1] = PAN_ID[1];
address_short_destination[0] = coord_address_short[0];
address_short_destination[1] = coord_address_short[1];
PAN_ID_source[0] = PAN_ID[0];
PAN_ID_source[1] = PAN_ID[1];
address_short_source[0] = rfd_address_short[0];
address_short_source[1] = rfd_address_short[1];
DATA_TX[0]=Ip_request;
DATA_TX[1]=0X00;
write_TX_normal_FIFO();
WHILE (!IP_REQUEST_FLAG){}
set_short_address(rfd_ADDRESS_short);
IP_REQUEST_FLAG=FALSE;
PRINTF(" IP REQUEST SUCCESSED!\r\n");
PRINTF(" MY IP_ADRESS IS: 0x0%D\r\n",ADRESS);
DATA_TX[0]=I_AM_LM35;
DATA_TX[1]=0X00;
write_TX_normal_FIFO();
//SETUP ADC
setup_adc_ports( ALL_ANALOG );
setup_adc(ADC_CLOCK_INTERNAL );
set_adc_channel( 0 );
while (1)
{
value = read_adc();
VALUE=VALUE*360/1023;
PRINTF(" NHIET DO: %D\r\n",VALUE);
DATA_TX[0]=DATA_SEND;
DATA_TX[1]=VALUE;
write_TX_normal_FIFO();
//! IF (SLEEP_MODE)
//! {
//! printf(" Sleeping...");
//! SLEEP_MODE=TRUE;
//! sleep();
//! }
delay_ms(1000);
}
}
|
When I add:
Code: |
SPBRG=spbrg_value; // Fill SPBRG register to set the baud rate
RCSTA.SPEN=1; // To activate serial port (Tx and Rx pins)
RCSTA.CREN=1; // To enable continuous reception
PIE1.RCIE=1; // To enable the Reception (Rx) Interrupt
INTCON.GIE=1;
INTCON.PEIE=1; |
CCS 4.1 errors : "Expecting a structure/union"
Who can help me repair it. _________________ Thinh |
|
![](templates/subSilver/images/spacer.gif) |
Knight_FlyCn
Joined: 10 May 2013 Posts: 16 Location: Việt Nam
|
|
Posted: Fri May 10, 2013 11:51 am |
|
|
I success
Code: | /* _CPUDIV_OSC1_PLL2_1L, // Divide clock by 2
_FOSC_HS_1H, // Select High Speed (HS) oscillator
_WDT_OFF_2H, // Watchdog Timer off
MCLRE_ON_3H // Master Clear on
*/
#include <RFD.h>
#include "def_18f4620.c"
#include "slave_1_tx_rx.h"
// Xac dinh ----
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#define SPI_MODE_0 (SPI_L_TO_H | SPI_XMIT_L_TO_H)
// Them vao
#ifndef FREQ
#define FREQ 4000000
#ifndef baud
#define baud 96000
#define spbrg_value (((FREQ/64)/baud)-1)
//
#bit CS = 0xF80.4
#bit RST = 0xF82.2
#bit INT_ = 0xF81.0
#bit WAKE = 0xF82.1
#bit CS_Direction = 0xF92.4
#bit RST_Direction = 0xF94.2
#bit INT_Direction = 0xF93.0
#bit WAKE_Direction = 0xF94.1
///////////////////////////////////////////////////////////////////////////////
// Command: 0x00: IP request //
// 0x01: I_AM_LM35 //
// 0x02: I_AM_PIR
INT TEMP;
int adress;
INT VALUE;
INT16 k=0;
const int IP_request=0x00,adress_surport=0x01,ip_surport=0x10;
int I_AM_LM35=0x01;
INT DATA_SEND=0X02;
INT COMMAND;//
INT1 IP_REQUEST_FLAG=FALSE;
SHORT SLEEP_MODE=true;
// Them vao
unsigned char card_id[10];
unsigned int i=0,pos;
//
//!#INT_RTCC
//!VOID NGAT_TIMER0()
//!{ printf("ngat timer0!");
//! ++;
//! IF (k>= 1000)
//! {
//! k=0;
//! SLEEP_MODE=FALSE;
//! }
//! TMR0IF=0;
//! disable_interrupts(INT_TIMER0);
//!}
//!
#INT_EXT
void ngat_RB0()
{
temp = read_ZIGBEE_short(INTSTAT); // Read and flush register INTSTAT
if ((temp&(1<<3))==(1<<3))
{
read_RX_FIFO();
COMMAND =DATA_RX[0];
SWITCH (COMMAND)
{
CASE ip_surport:
ADRESS=DATA_RX[1];
rfd_ADDRESS_short[1]=adress;
IP_REQUEST_FLAG=TRUE;
BREAK;
break;
}
}
}
void interrupt()
{
card_id[i]=RCREG; // Store the received data byte by byte
i++;
}
void main()
{
TRISB1=TRISB2=TRISB3=1;
TRISC0=TRISD3=0;
CS_Direction = 0; // Set direction to be output
RST_Direction = 0; // Set direction to be output
INT_Direction = 1; // Set direction to be input
WAKE_Direction = 0; // Set direction to be output
Delay_ms(5);
setup_spi(SPI_MASTER | SPI_MODE_0 | SPI_CLK_DIV_4); // Initialize SPI module
pin_reset(); // Activate reset from pin
software_reset(); // Activate software reset
RF_reset(); // RF reset
set_WAKE_from_pin(); // Set wake from pin
set_long_address(ADDRESS_long_1);
set_short_address(rfd_ADDRESS_short); // Set short address
set_PAN_ID(PAN_ID); // Set PAN_ID
init_ZIGBEE_nonbeacon(); // Initialize ZigBee module
nonbeacon_device();
set_TX_power(31); // Set max TX power
set_frame_format_filter(1); // 1 all frames, 3 data frame only
set_reception_mode(1); // 1 normal mode
enable_int();
pin_wake(); // Wake from pin
//enable interrupt ext
enable_interrupts(GLOBAL);
enable_interrupts(INT_EXT);
ext_int_edge(H_to_L);
// gioi thieu
printf("****************************************\r\n");
Printf(" ");
Printf(" RFD_designed by Huynh Thanh Dien\r\n");
Printf(" ");
printf("****************************************\r\n");
// IP request
printf(" Requesting IP...\r\n");
PAN_ID_destination[0] = PAN_ID[0];
PAN_ID_destination[1] = PAN_ID[1];
address_short_destination[0] = coord_address_short[0];
address_short_destination[1] = coord_address_short[1];
PAN_ID_source[0] = PAN_ID[0];
PAN_ID_source[1] = PAN_ID[1];
address_short_source[0] = rfd_address_short[0];
address_short_source[1] = rfd_address_short[1];
DATA_TX[0]=Ip_request;
DATA_TX[1]=0X00;
write_TX_normal_FIFO();
WHILE (!IP_REQUEST_FLAG){}
set_short_address(rfd_ADDRESS_short);
IP_REQUEST_FLAG=FALSE;
PRINTF(" IP REQUEST SUCCESSED!\r\n");
PRINTF(" MY IP_ADRESS IS: 0x0%D\r\n",ADRESS);
DATA_TX[0]=I_AM_LM35;
DATA_TX[1]=0X00;
write_TX_normal_FIFO();
////////////////////////////////////////////////////////////////////////////
// SET RX VA TX
SPBRG=spbrg_value; // Fill SPBRG register to set the baud rate
SPEN=1; // To activate serial port (Tx and Rx pins)
CREN=1; // To enable continuous reception
RCIE=1; // To enable the Reception (Rx) Interrupt
GIE=1;
PEIE=1;
while (1)
{
interrupt();
PRINTF(" MA SO THE: %D\r\n",card_id[10]);
DATA_TX[0]=DATA_SEND;
DATA_TX[1]=card_id[10];
write_TX_normal_FIFO();
//! IF (SLEEP_MODE)
//! {
//! printf(" Sleeping...");
//! SLEEP_MODE=TRUE;
//! sleep();
//! }
delay_ms(1000);
}
}
|
-------------------------------------------
Compile success
-------------------------------------------
People watching and commenting. RX pins of the 18F4620 connected to the RFID reader and read key tag . Save to "ard_id". And sent to the ZigBee module _________________ Thinh |
|
![](templates/subSilver/images/spacer.gif) |
senur
Joined: 11 Dec 2013 Posts: 13
|
|
Posted: Wed Dec 11, 2013 9:33 am |
|
|
I'm facing the same problem. May I know what you did? |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|