to begin, i want to say that my level in english is average, so forgive me for the mistakes..
i am a beginner in C programming and this is the first time i work with mikroC.
so i want to write a code and i need your help ..
the code should do the following :
first : PORTB.f0=1
when i send the letter 'c'
i must receive the data that is on the port 'RA0'
when i send again the letter 'c'
i must receive the data that is on the port 'RA1'
when i send again the letter 'c'
i must receive the data that is on the port 'RA2'
when i send again the letter 'c'
i must receive the data that is on the port 'RA3'
when i send again the letter 'c'
i must receive the data that is on the port 'RA5'
when i send again the letter 'c'
i must receive the data that is on the port 'RE0'
PORTB.f0=0
when i send the letter 'c'
i must receive the data that is on the port 'RA0'
when i send again the letter 'c'
i must receive the data that is on the port 'RA1'
when i send again the letter 'c'
i must receive the data that is on the port 'RA2'
when i send again the letter 'c'
i must receive the data that is on the port 'RA3'
when i send again the letter 'c'
i must receive the data that is on the port 'RA5'
when i send again the letter 'c'
i must receive the data that is on the port 'RE0'
now the code should return to the beginning and expected that i send the letter 'c'
---
I actually have this code
Code: Select all
float rtdv, rtdr, temp, y;
int msd, isd, i;
char temperature[6];
char uart_rd;
calcule()
{
rtdv=rtdv *5/1024;
rtdv=rtdv/5;
rtdr=rtdv*1000.0/(5.0-rtdv);
y=0.15274-(rtdr-100.0)*0.0002310;
if (y>=0)y = sqrt(y);
temp = (y-0.39083)/(-0.0001155);
bytetostr(temp,temperature);
delay_ms(1);
}
affichage()
{
UART1_Write_Text(temperature);
strcpy(temperature,"");
}
void main()
{
TRISA = 0xFF;
TRISE = 0xFF;
TRISB = 0x00;
PORTB = 1;
UART1_Init(9600);
while(1)
{ portb.f1=1;
if (UART1_data_ready())
{
uart_rd = UART1_read();
if(uart_rd=='c')
{
PORTB.f0=1;
for (i=0; i<6 ;i++)
{
delay_ms(5);
rtdv=adc_read(i);
UART1_Write(13);
calcule();
affichage();
}
PORTB.f0=~portb.f0;
for (i=0; i<6; i++)
{
delay_ms(5);
rtdv=adc_read(i);
UART1_Write(13);
calcule();
affichage();
}
}
}
}
}
in this code, when i sent the letter 'c' i receive all data contained on ports..
could you help me modify this code or write one that works according to algorthme above?