urgent help on PIC UART programming

Post your requests and ideas on the future development of mikroPascal PRO for PIC.
Post Reply
Author
Message
muktinathgogoi
Posts: 2
Joined: 08 Mar 2012 03:21

urgent help on PIC UART programming

#1 Post by muktinathgogoi » 08 Mar 2012 03:32

hii ...

actually i have to send microcontrollers internal ADC read data to the matlab continuously with the serial port.. adc is 10 bit.. and we know UART will read only 8 bit at atime.. so we have to split the 10 bit to two 8 bit data...

here i am advised to send the data serially to the uart through the Microcontroller as the following sting so that MATLAB recognize the data.....

start xx end

where first x represents higher order ADC bits & second x represents lower order ADC bits.

here start is used like a sync bit..

please help me to code it out..

previously i used to read the ADC value of port AN0 and send it continuously to UART .... this code is something like that:-

#include "built_in.h"

unsigned int adc_rd;



void main()
{
unsigned int temp_res;
Uart1_Init(9600);
ADCON0 = 0xC1;
ADCON1 = 0x8E; // Configure AN0 pin as analog
TRISA = 0xFF; // PORTA is input
TRISC = TRISC & 0xFC; // Pins RC7, RC6 are outputs
TRISB = 0x00; // PORTB is output
Delay_ms(100);
do
{
temp_res = ADC_Read(0); // Get 10-bit results of AD conversion
UART1_write(Lo(temp_res)); // Send lower 8 bits to UART
Delay_ms(100);
UART1_write(Hi(temp_res)); // Send upper 8 bits to UART
PORTB = Lo(temp_res); // Send lower 8 bits to PORTB
PORTC = Hi(temp_res); // Send 2 most significant bits to RC7, RC6
}while(1);
}

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: urgent help on PIC UART programming

#2 Post by filip » 08 Mar 2012 11:01

Hi,

Have you tried this on a real hardware ?

Regards,
Filip.

muktinathgogoi
Posts: 2
Joined: 08 Mar 2012 03:21

Re: urgent help on PIC UART programming

#3 Post by muktinathgogoi » 14 Mar 2012 08:14

ya... i am able to send the int adc data continuously to the UART.

but i am advised to send it to the UART module as a following string...


start1001000110end
start0111100101end
...........................
.......................etc

but i am not able to modyfy my string as that..(1001000110,0111100101 etc is the adc reading)

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: urgent help on PIC UART programming

#4 Post by filip » 16 Mar 2012 15:38

Hi,

Well, you should make a string for that, put the start sequence first, then add ADC result and append stop sequence.

Regards,
Filip.

Post Reply

Return to “mikroPascal PRO for PIC Wish List”