Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Microcontrollers receiving raw data from zigbee?

Status
Not open for further replies.
No. sending !A@ 1 time is the one time sequence,then micro check if !A@ is received turn on LED else turn OFF.

But my program now, i need to send at least 10times then is one time sequence and the LED will be ON. May i know whats wrong with my program? Thank You

- - - Updated - - -

sending !A@ 1 time is one time sequence then micro will check and on led else off led.

But now my program is send 10 times or more equal one sequence
 

Zip and post your complete Keil uVision project files. I will test it.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <reg51.h>
 
sbit mybit = P1^4;
 
unsigned char code start_header = '!';
unsigned char code end_header = '@';
unsigned char inforstart = 0;
unsigned char infor[20];
unsigned char inforcount = 0;
unsigned char i = 0;
 
 
void main(void){
 
    TMOD = 0x20;
        SCON = 0x50;
        TH1  = 0xFD;    
    TR1  = 1;
    EA=1;
    ES=1;
 
    mybit=0;
 
    while(1);
}
 
//send data as "!A@" and test
 
void serial_int(void)interrupt 4{
 
  if(RI);
  {
    infor[i++] = SBUF;
 
        
    if(i >= 3){
                     
            if((infor[0] == start_header) && (infor[1] == '!') && (infor[2] == end_header))mybit = 1;
             else mybit = 0;
        
            i = 0;           
        
    }    
  }
 
  RI = 0; 
}

 

thank you.
 

Attachments

  • working1.txt
    985 bytes · Views: 37

It works fine. You had selected Clock as 33 MHz. I have used 11.0592 MHz. Tested in Proteus. It is working fine.
 

Attachments

  • Desktop rev1.rar
    60.7 KB · Views: 39

By any chance do u know how to debounce the switch on zigbee. The situation now is when i press the button on zigbee it will send data but after i released the button it will send data too. But i want it to send only when i press and do nothing when i release the button.

9883812900_1383791423.png
 

do u know how to debounce the switch on zigbee

Where is the button? You said you are sending data from PC to micro using Zigbee. Where did the switch come in Zigbee? Do you mean the button in your PC software or do you have a button on Zigbee module?

In PC side software there is no need for a debounce.
 

the button is on the zigbee module. And i have stored the data (!A@) on the zigbee button. Button 1 is the button
 

Attachments

  • deve board.PNG
    deve board.PNG
    486.1 KB · Views: 51
Last edited:

Then the Zigbee chip will be programmed for debounce. How do you know that Zigbee is sending data more than one time if button is pressed? Did you check the o/p of Zigbee when button is pressed? If yes, how did you test. Explain the test setup.
 

test.PNG1. Zigbee on the left, it's button is set to set data to zigbee on the right.
2. Once i press the button, it will send a data but after i released the button multiple data was being sent too.
3. Zigbee on the right is to check what data its receiving.
 
Last edited:

there is no such option. So i was thinking to write a debounce code on microcontroller but i'm not sure how to go about writing it.
 

After receiving !A@ the first time disable Serial receive in ISR.

This receives!A@ only once.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
sbit mybit at P1_4_bit;
 
unsigned char infor[5];
unsigned char i = 0;
 
void SerialInterrupt() iv IVT_ADDR_ES ilevel 0 ics ICS_AUTO{
  
  if(RI_bit);
  {
    infor[i] = SBUF;
    i++;
  }
  
  if(i == 3){
       ES_bit = 0;
       EA_bit = 0;
  }
 
  RI_bit = 0;
 
}
 
void main(){
 
     P1 = 0x00;
     P3 = 0x03;
 
     TMOD = 0x20;
     SCON = 0x50;
     TH1  = 0xFD;
     TR1_bit  = 1;
     EA_bit = 1;
     ES_bit = 1;
 
     while(1){
 
            if(i == 3){
            
                    if((infor[0] == '!') && (infor[1] == 'A') && (infor[2] == '@'))
                    {
                             mybit = 1;
                    }
                    else mybit = 0;
                    
                    i = 0;
            }
     }
}

 
Last edited:

can i ask also, how do i initialize LCD to display the data i have received?
 

search for 4 bit LCD code in this forum. Send each received character to the LCD or make a function to sent string to LCD and then terminate the array which stores UART data with string termination character and send it to LCD function which prints strings.
 

hi, i have written the code but some error in it. May i know what command i should put inside the bracket which i highlighted. I tried putting SBUF but error C214: illegal pointer conversion occur.
9756608000_1383896060.png
 

Attachments

  • working2.txt
    2.2 KB · Views: 35


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include <ABSACC.h>
#include <reg51.h>
sbit mybit = P1^4;
 
 
unsigned char code start_header = '!';
unsigned char code end_header = '@';
unsigned char inforstart = 0;
unsigned char infor[20];
unsigned char inforcount = 0;
unsigned char i = 0;
void serial_int (void);
#define PortA 0x4000    //LCD data
#define PortB 0x4001    //LCD RS, RW, E
#define PortC 0x4002    //Keypad
#define ControlReg 0x4003
 
 
void Delay(int time)
{
    int i, j;
    for(i = 0; i < time; i++)
    for(j = 0; j < 200; j++);
}
 
 
void LCD_WriteInstructionReg(unsigned char Instruction)
{
    XBYTE[PortB] = 0x00;   
    XBYTE[PortB] = 0x04;     
    Delay(20);
    XBYTE[PortA]= Instruction;   
    XBYTE[PortB] = 0x00;   
}
 
void LCD_WriteDataReg(unsigned char Value)
{
    XBYTE[PortB] = 0x01;   
    XBYTE[PortB] = 0x05;     
    Delay(20);
    XBYTE[PortA] = Value;  
    XBYTE[PortB] = 0x00;   
} 
 
 
 
void InitialiseLCD(void)
{
 
    LCD_WriteInstructionReg(0x38);  //8 bits bus mode, 2 line display, 5x7 dots 
 
format
    LCD_WriteInstructionReg(0x0E);  //TurnOn display, cursor on, no blink
    LCD_WriteInstructionReg(0x01);  //ClearDisplay
    LCD_WriteInstructionReg(0x06);  //Increase cursor to right
    LCD_WriteInstructionReg(0x02);  //ReturnHome
}
 
void LCD_DisplayString(char *String)
{
    int i = 0;
    while (String[i])
    {
        LCD_WriteDataReg(String[i++]);
    }
}
 
 
 
void main(void){
 TMOD = 0x20;
        SCON = 0x50;
        TH1  = 0xFD;    //9600 bps
    PCON=0x80;
        TR1  = 1;
    EA=1;
ES=1;
    mybit=0;
    serial_int();
    Delay(5000);   //waiting for PPI to reset
    XBYTE[ControlReg] = 0x81;   
    InitialiseLCD();
    LCD_DisplayString("Zigbee");
    while(1){
 
        infor[3] = '\0';
        LCD_WriteInstructionReg(0xC0);
        LCD_DisplayString(infor);
    }
}
 
//send data as "!A@" and test
 
void serial_int (void) interrupt 4{
 
  if(RI==1);
  {
    infor[i++] = SBUF;
 
    if (infor[0] =='!')     
    {   
        inforstart = 1;
        inforcount = 0;
    }
    
    if(inforstart == 1)
    {
        if (infor[2] =='@')
        {   
            inforstart = 0;
                    
       if((infor[0]=='!')&&(infor[1] == 'A')&&(infor[2]=='@'))  
                { 
                 mybit = 1;
                }
                    else mybit=0;
                    i=0;
            
          
            
        }
    }
    
    
  }
 
  RI = 0; 
}

 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top