caramoan tour package

caramoan tour package

Author Topic: Receiving data from UART using UP IRC Slimboard  (Read 362 times)

Offline cylindrical

  • CR2032 Battery
  • **
  • Posts: 19
  • Pogi/Ganda Points: 0
Receiving data from UART using UP IRC Slimboard
« on: March 10, 2012, 03:23:20 AM »
Gamit ko yung IRC Slimboard na may Z8F6421 and yung AC Power Analyzer Kit ng e-Gizmo. Connected na silang dalawa using UART. Now, yung AC Power Analyzer Kit is supposed to send a string to the MCU. My problem is, pano ko makukuha yung data na yun at mai-manipulat4e sa program?

Nag-search ako sa internet, dito sa forums, at pati sa CD na kasama nung mga kits. Ito lang ang nakuha ko:

Code: [Select]
/******************** Hello World! *********************/
/* This program displays text on the HyperTerminal and */
/* makes the LEDs connected to PA0 and PA1 blink.      */

#include <ez8.h>
#include <stdio.h>
#include <sio.h>

#define GPIO_PORT 0x02

void initGPIO(void){
PADD &= ~GPIO_PORT; // data direction: output
PAAF &= ~GPIO_PORT; // alternate function: off
}

void delay(void){
unsigned char i,j;

for(i = 0; i < 0xFF; i++)
for(j = 0; j < 0xFF; j++);
}

int main(void){
init_uart(_UART1, _DEFFREQ, _DEFBAUD);
initGPIO();

// printf("Hello World\n");

while(1){
if (!(PBIN & 0x01)){

printf("tumutunog\n");
PAOUT |= GPIO_PORT;

delay();
delay();
delay();
}
else {
printf("tahimik\n");
PAOUT &= ~GPIO_PORT;
}
}
}

Yung pinakamalapit na nakuha is yung:
Code: [Select]
init_uart(_UART1, _DEFFREQ, _DEFBAUD);at yung:
Code: [Select]
select_port(_UART0);kaso, if i'm correct, initialization lang ng UART yun.

Pano ako makaka-receive ng data from the UART gamit yung IRC slimboard?

Philippine Electronics Forum

Receiving data from UART using UP IRC Slimboard
« on: March 10, 2012, 03:23:20 AM »

Offline RiDdLeR???

  • Hydroelectric
  • ***
  • Posts: 3032
  • Pogi/Ganda Points: 208
Re: Receiving data from UART using UP IRC Slimboard
« Reply #1 on: March 10, 2012, 07:59:55 AM »
gamit ka ng "gets" or "getch" from the library

Philippine Electronics Forum

Re: Receiving data from UART using UP IRC Slimboard
« Reply #1 on: March 10, 2012, 07:59:55 AM »

Offline cylindrical

  • CR2032 Battery
  • **
  • Posts: 19
  • Pogi/Ganda Points: 0
Re: Receiving data from UART using UP IRC Slimboard
« Reply #2 on: March 10, 2012, 05:13:00 PM »
Eh diba po yung gets() at getch() eh mag-wait ng input from user? What I'm trying to do is to get the data sent to the UART then display it on the screen.

Philippine Electronics Forum

Re: Receiving data from UART using UP IRC Slimboard
« Reply #2 on: March 10, 2012, 05:13:00 PM »

Offline cylindrical

  • CR2032 Battery
  • **
  • Posts: 19
  • Pogi/Ganda Points: 0
Re: Receiving data from UART using UP IRC Slimboard
« Reply #3 on: March 12, 2012, 08:34:24 PM »
Pa-help po. Nag-eerror po yung code namin.

Code: [Select]
#include <ez8.h>
#include <uart.h>
#include <sio.h>

void delay(void) {

}

char read_data_from_uart(void)
{
UART uart ;
char *readdata;
int len;
char stat = UART_ERR_NONE ;
/* configure UART0 with 9600 baud, 1 stop bits
and no parity */
uart.baudRate = BAUD_9600 ;
uart.stopBits = STOPBITS_1 ;
uart.parity = PAR_NOPARITY ;
/*! Configure the UART */
stat = control_UART0( &uart ) ;
if( UART_ERR_NONE != stat ) { return stat; }
stat = read_UART0( readdata, &len ) ;
if( UART_ERR_NONE != stat )
{
close_UART0();
return stat;
}
/*! block here while receiver is busy */
while(UART_IO_PENDING == get_rxstatus_UART0());
close_UART0();
}

void main(void) {
char s = read_data_from_uart();
printf("%s",s);
while(1);
}

Ang error po ay:
Code: [Select]
FATAL ERROR (724) --> Symbol _read_UART0 (.\main.obj) is not defined.Di ko po maintindihan kasi nasa uart.h naman yung read_UART0().

Philippine Electronics Forum

Re: Receiving data from UART using UP IRC Slimboard
« Reply #3 on: March 12, 2012, 08:34:24 PM »

 

Privacy Policy

Contact Us: elabph@yahoo.com