mikroC compiler problem

Status
Not open for further replies.

oday_albadarneh

Newbie level 6
Joined
Dec 20, 2011
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,380
Hi all
I was working on my project for more than month i stuck in a problem that the hardware serial communication doesn't work or it sends me a rubbish values.
may any one help me to convert my code to hex file on his compiler and try it on real pic ?!!
i will be thankful to all of you, i need it as soon as possible.
the attached code needed to be included with default setting for serial connection with 4 Mhz XT
Code:
// variables
float vc1,vc2,vc3,beta;
char vc1_txt[15],vc2_txt[15],vc3_txt[15],beta_txt[15],adder_txt[15];
int check;
char uart_rd,adder,lock,add1,add2,receive;

void calculate_beta ()
{
    beta = ((5 - vc1)* 1000000) / ((5-.7)*3700 ) ;
    FloatToStr(beta,beta_txt);
    Delay_ms(2000);
    UART1_Write_Text(beta_txt);
    Uart1_Write(13);
    Uart1_Write(10);
    Delay_ms (2000);
}

void Calculate_vc1()
 {
    vc1 = ADC_Read(0);
    vc1 = 0.004887585533*vc1;
    if (vc1 <= 0.2 )
         UART1_Write_Text("S");
    else if (vc1 > 0.2 && vc1 < 4.85 )
         UART1_Write_Text("F");
    else if (vc1 > 4.85)
         UART1_Write_Text("C");

    Uart1_Write(13);
    Uart1_Write(10);
    delay_ms(2000);
 }

void Calculate_vc2()
 {
    vc2 = ADC_Read(1);
    vc2 = 0.004887585533*vc2;
    if (vc2 <= 0.2 )
         UART1_Write_Text("S");
    else if (vc2 > 0.2 && vc2 < 4.85 )
         UART1_Write_Text("F");
    else if (vc2 > 4.85)
         UART1_Write_Text("C");

    Uart1_Write(13);
    Uart1_Write(10);
    delay_ms(2000);
 }

void Calculate_vc3()
 {
    vc3 = ADC_Read(2);
    vc3 = 0.004887585533*vc3;
    if (vc3 <= 0.2 )
         UART1_Write_Text("S");
    else if (vc3 > 0.2 && vc3 < 4.85 )
         UART1_Write_Text("F");
    else if (vc3 > 4.85)
         UART1_Write_Text("C");

    Uart1_Write(13);
    Uart1_Write(10);
    delay_ms(2000);

 }

void lock_check ()
 {
     PORTD = lock & 0x0F ;
     delay_ms (1500) ;
     check = PORTD.F4 ;
     if (check == 1)
         UART1_Write_Text("NO GO");
     else if (check == 0)
         UART1_Write_Text("GO");
    Uart1_Write(13);
    Uart1_Write(10);
    delay_ms(2000);
  }

void full_adder (char a , char b)
 {
   PORTB = ( a & 0x0F )+ ( b & 0xF0 );
   adder = PORTC ;
   adder = adder & 0x1F;
   ByteToStr(adder,adder_txt);
   Uart1_Write_Text(adder_txt);
   Uart1_Write(13);
   Uart1_Write(10);
   delay_ms (2000);

 }


void main() {

     ADRESL = 0x00;
     ADRESH = 0x00;
     TRISA  = 0xFF;
     TRISB  = 0x00;
     TRISC  = 0x9F;
     TRISD  = 0x70;
     CMCON  = 0x07;

     UART1_Init(9600);      // Initialize UART module at 9600 bps
     Delay_ms(100);         // Wait for UART module to stabilize



    while (1) {

            UART1_Write_Text("#");
            while(!UART1_Data_Ready());
            uart_rd = UART1_Read();
            UART1_Write_Text("\r\n");
            Delay_ms(500);
            
            if (uart_rd == 0x31) {
            calculate_beta();
            Delay_ms(500);}
            
            else if ( uart_rd == 0x32) {
            Calculate_vc1();
            Delay_ms(500);}
            
            else if ( uart_rd == 0x33) {
            Calculate_vc2();
            Delay_ms(500);}
            
            else if ( uart_rd == 0x34) {
            Calculate_vc3();
            Delay_ms(500);}
            
            else if ( uart_rd == 0x35)
            {
            Uart1_Write(0x61);
            delay_ms(2000);
            UART1_Write_Text("\r\n");
            while(!UART1_Data_Ready());
            lock = UART1_Read();
            lock_check();
            Delay_ms(500);
            }
            
            else if ( uart_rd == 0x36)
            {
            PORTD.F7 =0 ;
            Uart1_Write(0x61);
            UART1_Write_Text("\r\n");
            delay_ms(500);
            while(!UART1_Data_Ready());
            add1 = UART1_Read();
            Uart1_Write(0x62);
            UART1_Write_Text("\r\n");
            delay_ms(500);
            while(!UART1_Data_Ready());
            add2 = UART1_Read();
            full_adder (add1 , add2);
            Delay_ms(500); 
            }
            
            else if ( uart_rd == 0x37)
            {
            PORTD.F7 =1 ;
            Uart1_Write(0x61);
            delay_ms(500);
            UART1_Write_Text("\r\n");
            while(!UART1_Data_Ready());
            add1 = UART1_Read();
            Uart1_Write(0x62);
            delay_ms(500);
            UART1_Write_Text("\r\n");
            while(!UART1_Data_Ready());
            add2 = UART1_Read();
            full_adder (add1 , add2);
            Delay_ms(500);
            }
            
          else
            break ;


    }
}
 

You had the same problem sometime back. Now you have modified your code. right? I think the problem is with your MAX232.
Here are the hex and cof files compiled for 4 MHz.
 

Attachments

  • uart.rar
    12.6 KB · Views: 86

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…