Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

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;   }

        }
        }
 

hexreader

Advanced Member level 2
Joined
Apr 7, 2011
Messages
536
Helped
194
Reputation
392
Reaction score
196
Trophy points
1,323
Location
England
Activity points
4,680
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.
 

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
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 ?
 

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
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;
        }

    }
}
 

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
i am connecting the PIC pins to this L293D breakout board

141220121393.jpg
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top