Hello Sir,
I want to send some data through UART when i press S1 button on evalution board.
On power on the device, it should run in PM2, When i press s1 button device must wake up from PM2 to PM0 and then should send some data.
After sending data it must go back to PM2 again.
i have written below code.. it is working fine when i debug & run it through IAR embedded workbench IDE..
but after dumping it on chip, switch off that board and switching on, then on pressing s1 button the device is sending data but again it is not sending on pressing S1 button..
//=====================================
#include "hal_types.h"
#include "hal_defs.h"
#include "hal_cc8051.h"
#include "ioCCxx10_bitdef.h"
#if (chip == 2510)
#include <ioCC2510.h>
#endif
//static uint32 __xdata Cnt = 0 ;
uint8 i = 0 ;
uint16 j=0;
//==============================================================================
#pragma vector = 0x6B
__interrupt void PM0_ISR(void)
{
P0IFG &= ~BIT1;
P0IF = 0;
// Clear the [SLEEP.MODE] bits.
SLEEP &= ~SLEEP_MODE;
// Set SRF04EB LED1 to indicate Power Mode 2
P1_0 = 0;
}
//==============================================================================
void uart0send()
{
U0BAUD=59; // For 9600 baud rate
U0GCR=(U0GCR & ~0x1F)|8;
U0CSR|=0x80; //Asynch
U0UCR=(U0UCR&~83)|0x02;
U0GCR&=~0x20;
PERCFG &= ~0x01;
P0SEL|=0x3c;
P1SEL&=~0x3c;
CLKCON&=0x80;
while(CLKCON & 0x40);
SLEEP|=0x04;
UTX0IF=0;
for (i=65; i<=81; i++)
{
if(i>64&&i<91)
{
U0DBUF = i;
}
while(!UTX0IF);
UTX0IF=0;
}
}
//==============================================================================
void main(void)
{
P1SEL &= ~0x06;
P1_0 = 1;
P1_3 = 1;
P1DIR |= 0x09;
P0IFG &= ~0x0D;
PICTL = (0x8C & ~0x01) | 0x08;
SLEEP &= ~0x04;
while(!(SLEEP & 0x20)); // Wait until HF RCOSC is stable
CLKCON = (CLKCON & ~(0x07 | 0x40)) | (0x00);
while (CLKCON & 0x40);
SLEEP |= 0x06;
P0IE = 1;
EA = 1;
if(SLEEP& 0x03)
{
PCON |= 0x01;
uart0send();
P1_0 = 0;
}
}
//==============================================================================
Also i need to wake up device from PM3 to PM0 & then send data through uart, when ever i select s1 button..!
later after sending data it must go back to pm3 mode.. again on pressing s1 button device must wake & data must send.. if flow should happen..
i have written below code.. getting same problem as above pm2-pm0 shifting..
#include "hal_types.h"
#include "hal_defs.h"
#include "hal_cc8051.h"
#include "ioCCxx10_bitdef.h"
#if (chip == 2431)
#include "ioCC2431.h"
#endif
static char __xdata XData[26]="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
uint16 j=0;
uint8 i=0;
//==============================================================================
#pragma vector = 0x6B
__interrupt void PM0_ISR(void)
{
P0IFG = 0x00;
P0IF = 0;
//SLEEP &= ~SLEEP_MODE;// Clear the [SLEEP.MODE] bits
P1_0 = 1;
}
//==============================================================================
void uart0send()
{
U0BAUD=59; // For 9600 baud rate
U0GCR=(U0GCR & ~0x1F)|8;
U0CSR|=0x80; //Asynch
U0UCR=(U0UCR&~83)|0x02;
U0GCR&=~0x20;
PERCFG &= ~0x01;
P0SEL|=0x3c;
P1SEL&=~0x3c;
CLKCON&=0x80;
while(CLKCON & 0x40);
SLEEP|=0x04;
UTX0IF=0;
for (i=0; i<=25; i++)
{
if(XData[i]>='A' && XData[i]<='Z')
{
U0DBUF = XData[i];
while(!UTX0IF);
UTX0IF=0;
}
}
}
//==============================================================================
void main(void)
{
P1SEL &= ~0x06;
P1_0 = 1;
P1_3 = 1;
P1DIR |= 0x09;
P0IF = 0;
P0IFG &= 0x00;
PICTL = 0x08;
SLEEP &= ~0x04;
while(!(SLEEP & 0x20)); // Wait until HF RCOSC is stable
CLKCON = (CLKCON & ~(0x07 | 0x40)) | (0x01);
while (CLKCON & 0x40);
SLEEP |= 0x07; // PM 3
P0IE = 1;
EA = 1;
PCON |= 0x01;
uart0send();
P1_0 = 0;
}
//==============================================================================