CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

How can i read from serial ??

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
noyz



Joined: 31 Jan 2009
Posts: 59

View user's profile Send private message

How can i read from serial ??
PostPosted: Sat Jun 25, 2011 9:50 am     Reply with quote

hi
how can i read from serial ?
i want to use interrupts..

so that i will have only one part where i can read from serial
and before that i will enable interrupts int rda
and then disable;


i want to read int from serial.. so i need to transform it also.. from string to int ..atoi ?
can you show me an example please?

i am trying this :

Code:

#include <18F8527.h>
#device adc=10
#device PASS_STRINGS=IN_RAM
#use delay(clock=32 000 000,RESTART_WDT)
#fuses H4, NOPUT, NOLVP, NOMCLR, NOWDT        //WDT128  //BORV27
#use rs232(baud=115200,xmit=PIN_C6,rcv=PIN_C7,bits=8,restart_wdt)  //PIC Uart
#include <stdlib.h>

#define BUFFER_SIZE 32
BYTE buffer[BUFFER_SIZE];
BYTE BUFFER_INDEX = 0;
char serialInput[20];
#INT_RDA
void serial_isr () {

     do {
         buffer[BUFFER_INDEX] = getch ();
         BUFFER_INDEX++;
     } while (buffer[BUFFER_INDEX - 1] != '\r');
     BUFFER_INDEX = 0;
}


void main () {

     setup_adc_ports ( AN0_TO_AN1 );
     setup_adc ( ADC_CLOCK_INTERNAL );
     setup_psp ( PSP_DISABLED );
     setup_spi ( SPI_MASTER | SPI_CLK_DIV_16 | SPI_H_TO_L | SPI_XMIT_L_TO_H );
     //     SETUP_SPI ( SPI_MASTER | SPI_SS_DISABLED | SPI_H_TO_L | SPI_CLK_DIV_16  | SPI_XMIT_L_TO_H );
     //     setup_timer_0(RTCC_INTERNAL|RTCC_DIV_2);
     setup_timer_1 ( T1_DISABLED );
     setup_timer_2 ( T2_DISABLED, 0, 1 );
     setup_timer_3 ( T3_DISABLED | T3_DIV_BY_1 );
     //   enable_interrupts ( INT_RTCC );
     //   enable_interrupts ( INT_RB );
     disable_interrupts ( INT_AD );
     //     enable_interrupts ( INT_RDA );
     disable_interrupts ( INT_RDA );
     enable_interrupts ( GLOBAL );

     printf ( "start" );
     while (true) {
         printf ( "this : " );
         delay_ms ( 300 );


          enable_interrupts ( INT_RDA );
         delay_ms ( 200 );

         disable_interrupts ( INT_RDA );
         printf ( buffer );
         printf ( "\r\n" );
     }
}



Last edited by noyz on Sat Jun 25, 2011 10:00 am; edited 2 times in total
temtronic



Joined: 01 Jul 2010
Posts: 9162
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Jun 25, 2011 9:52 am     Reply with quote

Several examples are in the 'examples' folder( go figure !) that CCS supplies when you purchase the compiler.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Jun 25, 2011 1:25 pm     Reply with quote

If you want to read the output from a GPS or from a cell phone, you
should come right out and tell us. There are many examples on the
forum that we can link you to (or you could search for them), and it
would save a lot of time about guessing what you really want.
noyz



Joined: 31 Jan 2009
Posts: 59

View user's profile Send private message

PostPosted: Thu Jun 30, 2011 11:06 am     Reply with quote

I have an application with pic18f2550 which reads how much power one consumer drains in that moment.
So a watt reader.
I set serial there.. the output is ok to pc.
Now I want to read it on 8527 and draw a graph.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jun 30, 2011 11:31 am     Reply with quote

Post the manufacturer and model number of the wattmeter and post
a link to its specification which shows the serial protocol that it outputs.
You need to post information for us to answer the question.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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