pabel971123
Newbie level 3
Hi,
I want to measure distance between two points using rf. I am using msp430f5528 microcontroller which uses 24 MHz crystal oscillator . It is based on tof technology. First msp430 sends a data through rf and switch on a timer. Other side receiver receives it and sends an acknowledge signal. msp430 receives this and switch off the timer. Then calculate the distance.
Now in program I want to display the timer value on an lcd and calculate the distance manually for clarity. The program is:
In this code I am displaying the timer value on lcd to calculate the distance, but it is not displaying.
Please help me in this.
Thanks
Pabel
I want to measure distance between two points using rf. I am using msp430f5528 microcontroller which uses 24 MHz crystal oscillator . It is based on tof technology. First msp430 sends a data through rf and switch on a timer. Other side receiver receives it and sends an acknowledge signal. msp430 receives this and switch off the timer. Then calculate the distance.
Now in program I want to display the timer value on an lcd and calculate the distance manually for clarity. The program is:
Code:
#include <msp430.h>
#define DR P4OUT = P4OUT | BIT1 // define RS high
#define CWR P4OUT = P4OUT & (~BIT1) // define RS low
#define READ P4OUT = P4OUT | BIT2 // define Read signal R/W = 1 for reading
#define WRITE P4OUT = P4OUT & (~BIT2) // define Write signal R/W = 0 for writing
#define ENABLE_HIGH P1OUT = P1OUT | BIT4 // define Enable high signal
#define ENABLE_LOW P1OUT = P1OUT & (~BIT4) // define Enable Low signal
unsigned int i;
unsigned int j;
void delay(unsigned int k)
{
for(j=0;j<=k;j++)
{
for(i=0;i<100;i++);
}
}
void data_write(void)
{
ENABLE_HIGH;
delay(2);
ENABLE_LOW;
}
void data_read(void)
{
ENABLE_LOW;
delay(2);
ENABLE_HIGH;
}
void check_busy(void)
{
PJDIR &= ~(BIT3); // make P1.3 as input
while((PJIN&BIT3)==1)
{
data_read();
}
PJDIR |= BIT3; // make P1.3 as output
}
void send_command(unsigned char cmd)
{
check_busy();
WRITE;
CWR;
PJOUT = (PJOUT & 0xF0)|((cmd>>4) & 0x0F); // send higher nibble
data_write(); // give enable trigger
PJOUT = (PJOUT & 0xF0)|(cmd & 0x0F); // send lower nibble
data_write(); // give enable trigger
}
void send_data( char data)
{
check_busy();
WRITE;
DR;
PJOUT = (PJOUT & 0xF0)|((data>>4) & 0x0F); // send higher nibble
data_write(); // give enable trigger
PJOUT = (PJOUT & 0xF0)|(data & 0x0F); // send lower nibble
data_write(); // give enable trigger
}
void send_string(char *s)
{
while(*s)
{
send_data(*s);
s++;
}
}
void lcd_init(void)
{
PJDIR |= 0xFF;
PJOUT &= 0x00;
P4DIR |= 0xFF;
P4OUT &= 0x00;
P1DIR |= 0xFF;
P1OUT &= 0x00;
send_command(0x33);
send_command(0x32);
send_command(0x28); // 4 bit mode
send_command(0x0E); // clear the screen
send_command(0x01); // display on cursor on
send_command(0x06); // increment cursor
send_command(0x80); // row 1 column 1
}
char data;
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P4SEL = BIT4+BIT5; // P3.4,5 = USCI_A0 TXD/RXD
UCA1CTL1 |= UCSWRST; // **Put state machine in reset**
UCA1CTL1 |= UCSSEL_2; // SMCLK
UCA1BR0 = 6; // 1MHz 9600 (see User's Guide)
UCA1BR1 = 0; // 1MHz 9600
UCA1MCTL = UCBRS_0 + UCBRF_13 + UCOS16; // Modln UCBRSx=0, UCBRFx=0,
// over sampling
UCA1CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
UCA1IE |= UCRXIE; // Enable USCI_A0 RX interrupt
UCA1TXBUF = 3; // TX -> RXed character
__bis_SR_register(LPM0_bits + GIE); // Enter LPM0, interrupts enabled
__no_operation(); // For debugger
}
// Echo back RXed character, confirm TX buffer is ready first
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=USCI_A1_VECTOR
__interrupt void USCI_A1_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(USCI_A1_VECTOR))) USCI_A1_ISR (void)
#else
#error Compiler not supported!
#endif
{
switch(__even_in_range(UCA1IV,4))
{
case 0:break; // Vector 0 - no interrupt
case 2:
TA0CTL = MC__STOP;
// Vector 2 - RXIFG
data=TA0R;
lcd_init();
char data1=data%10 + 0x30;
send_string(&data1);
data=data/10;
data1=data%10 + 0x30;
send_string(&data1);
data=data/10;
data1=data%10 + 0x30;
send_string(&data1);
data=data/10;
data1=data%10 + 0x30;
send_string(&data1);
data=data/10;
data1=data%10 + 0x30;
send_string(&data1);
TA0CTL |=TACLR;
while (!(UCA1IFG&UCTXIFG)); // USCI_A0 TX buffer ready?
UCA1TXBUF = UCA1RXBUF; // TX -> RXed character
TA0CCR0 = 65535;
TA0CTL = TASSEL_2 + MC_1 + TACLR; // SMCLK, upmode, clear TAR
break;
case 4:
break; // Vector 4 - TXIFG
default: break;
}
// __bic_SR_register_on_exit (LPM0_bits);
}
In this code I am displaying the timer value on lcd to calculate the distance, but it is not displaying.
Please help me in this.
Thanks
Pabel