16f877a uart mikroc proteus help

Status
Not open for further replies.

Rohith_elec

Full Member level 4
Joined
Dec 16, 2011
Messages
198
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,296
Activity points
2,470
my code for uart like below not working as expected in proteus

Code:
char  receive ;



void main() {
    CMCON |= 7;
    TRISA = 0x04;                    // RA2 is analogue input
    ADCON1 = 0x80;
    TRISD =0;                       //
    PORTD=0x00;



    while (1) {



        UART1_Init(9600);               // Initialize UART1 module at 9600 bps
        Delay_ms(100);                  // Wait for UART 1module to stabilize
        UART1_Write_Text("Start");
        UART1_Write(13);
        UART1_Write(10);



        while (!UART1_Data_Ready());        // wait for UART character in buffer
        {receive = UART1_Read();
        if (receive == 'a')
        {
        portd=0x00;
         portd.f0=0;
         portd.f1=0;
         portd.f2=1;

         }

       if (receive == 'b')
          portd=0x00;
         portd.f0=1;
         portd.f1=1;
         portd.f2=1;   }

        }
        }
 

This tidied-up and fixed code works for me on real hardware:

Code:
char  receive ;

void main(){
    CMCON |= 7;                         // turn off comparator
    TRISA = 0x04;                       // RA2 is analogue input
    ADCON1 = 0x80;
    TRISD = 0;                          //
    PORTD = 0x00;

    UART1_Init(9600);                   // Initialize UART1 module at 9600 bps
    Delay_ms(100);                      // Wait for UART 1module to stabilize
    UART1_Write_Text("Start\r\n");

    while (1) {
        while (!UART1_Data_Ready());        // wait for UART character in buffer

        receive = UART1_Read();

        if (receive == 'a'){
            PORTD = 0x04;
        }

        if (receive == 'b'){
            PORTD = 0x07;
        }
    }
}
I have no idea about Proteus, as I never use it.
 
I want to use this inside a rover robot , just turn the motor using uart.
The uart connection restarts when the robot is moved forward and suddenly take backwards,
is this because the voltage variation caused when the motor is toggled suddenly ?
 

Here is my new code

Code:
char  receive ;

void main(){
    CMCON |= 7;                         // turn off comparator
    TRISA = 0x04;                       // RA2 is analogue input
    ADCON1 = 0x80;
    TRISD = 0;                          //
    PORTD = 0x00;

    UART1_Init(9600);                   // Initialize UART1 module at 9600 bps
    Delay_ms(100);                      // Wait for UART 1module to stabilize
    UART1_Write_Text("Start\r\n");

    while (1) {
        while (!UART1_Data_Ready());        // wait for UART character in buffer

        receive = UART1_Read();

        if (receive == 'f'){
            PORTD = 0x2D;
            
        }

        if (receive == 'b'){
            PORTD = 0x1B;
        }
        
         if (receive == 'r'){
            PORTD = 0x2B;
        }
        
         if (receive == 'l'){
            PORTD = 0x1D;
        }

    }
}
 

i am connecting the PIC pins to this L293D breakout board

 

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…