0% found this document useful (0 votes)
324 views3 pages

Pic C Sample Code Rs232

This sample code will work for a pH / OPR / Dissolved Oxygen Stamp. You must enable the fallowing libraries: C_String UART Software UART char input. If we get an interrupt from the rx pin / / we read the incoming chars until we receive a ( " / r") or 20 chars.

Uploaded by

Med Hilalisme
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
324 views3 pages

Pic C Sample Code Rs232

This sample code will work for a pH / OPR / Dissolved Oxygen Stamp. You must enable the fallowing libraries: C_String UART Software UART char input. If we get an interrupt from the rx pin / / we read the incoming chars until we receive a ( " / r") or 20 chars.

Uploaded by

Med Hilalisme
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

AtlasScientific

Biology Technology

C Sample Code
THIS CODE WAS WRTEN FOR A PIC 18f14k50 using the Mikro C pro Compiler. Change the sample code to fit your processor this sample code will work for a pH/OPR/Dissolved Oxygen Stamp you must enable the fallowing libraries: C_String|UART|Software UART char input[20]; volatile bit rx_event; void interrupt() { if (PIR1.RCIF) { UART1_Read_Text(input, "\r", 20); rx_event=1; } void main() { short Start_up=0; short i; //used to control the start-up sequence //counter // if we get an interrupt from the RX pin // we read the incoming chars until we receive a <CR> ( "/r") or 20 chars // set rx_event=1 so we know data is holding // this char array is used to store the RX input data //this is a bit var to signal an rx receive event // all interrupts are dealt with here

//set up system clock to run at 8 MHz OSCCON.b6=1; OSCCON.b5=1; OSCCON.b4=0; OSCCON.b1=1; //set up hardware uart system UART1_Init(38400); ANSELH.ANS11 =0; IOCB.IOCB7=0; TRISB.TRISB7=0; TRISB.TRISB5=1;
Atlas-Scientific.com

//turn off analog functions on the RX pin //interrupt on change pin, disabled //config TX as output //config RX as input

Copyright Atlas Scientific LLC

All Rights Reserved

AtlasScientific
Biology Technology
Soft_UART_Init(&PORTB, 4, 6, 38400, 0); // Initialize Soft UART at 38400 bps ^..........................port to be used ^.....................RX pin (we are to going to use the RX function) ^.................TX pin (pin 11) ^.............baud rate 38400 ^........rs-232 data is NOT inverted

//CONFIG UART INTERUPTERS INTCON.PEIE = 1; //peripheral interrupt enable PIE1.RCIE = 1; //Receive char Interrupt Enable bit PIR1.RCIF = 0; //Receive char Interrupt flag- reset to 0 INTCON.GIE = 1; //global interrupt enable rx_event=0; //initialize rx_evnet to = 0

delay_ms(1000); if(Start_up==0){ for(I = 1; I<=3;i++){ uart1_write_text("L0"); uart1_write(13); delay_ms(1000); uart1_write_text("L1"); uart1_write(13); delay_ms(1000);

//wait one sec for the stamp to stabilize //when the program firsts starts it will //flash on / off the stamps led //"L0" = led's off //<CR> //wait one sec //"L1" = led's on //<CR> //wait one sec //by setting Start_up to 1, we stop the leds from flashing on/off

} Start_up = 1;

Atlas-Scientific.com

Copyright Atlas Scientific LLC

All Rights Reserved

AtlasScientific
Biology Technology
delay_ms(1000); uart1_write_text("c"); uart1_write(13); delay_ms(500); while(1){ short len=0; if(rx_event){ rx_event=0; len = strlen(input); for(i=0;i<len;i++){ Soft_UART_Write(input[i]); } Soft_UART_Write(13); } //reset rx_event to 0 //we need to know the length of the string we just received from the stamp is //we now loop through each char of the char array "input" //now we output each char through the soft serial port // when we finish outputting the data, we end with a <CR> //wait one sec for the stamp to stabilize after the led flashing //the command "c" will tell the stamp to take continues readings //<CR>

} }

Atlas-Scientific.com

Copyright Atlas Scientific LLC

All Rights Reserved

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy