ali shaheen
Junior Member level 1
- Joined
- Aug 29, 2010
- Messages
- 15
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Location
- pakistan, karachi
- Activity points
- 1,419
hello,
i had developed a code and the schematic for serial communication through pic18f452 ...using max 232...and rs232 cable...I have used PROTEUS ISIS to simulate the circuit....the code below will work when the either one of the two cases goes true....and and it is working but the problem i am facing is that in simulation when I execute the program and load the hex file in the controller in simulation its not working on the keys i defined for clockwise and ant- clockwise direction but it is moving clockwise when i press '2' and anti clockwise when i press '6'......and also if i change the characters for input they are not working for them......only '2',and '6' are working through numeric keypad....while between execution in ISIS the vitual terminal is also not showing the characters or any junk value.......I hope i defined my problem in suitable manner....please help...am in a great great trouble.........
bestregards
ALI SHAHEEN
****************the code***************
//the code is in mikroCv8.2
//using pic18f452
unsigned short i;
void main() {
portd=0;
trisd=0;
portb=0;
trisb=0;
// Initialize USART module (8 bit, 9600 baud rate, no parity bit..)
Usart_Init(9600);
do {
if (Usart_Data_Ready()) { // If data is received
i = Usart_Read(); // Read the received data
switch(i)
{
case'3': //clockwise
portd.rd0=1 ;
portd.rd1=0;
////////////
PORTD.RD2=1; //OUTPUT
PORTD.RD3=0;
PORTD.RD4=0;
PORTD.RD5=0;
DELAY_MS(50);
//lcdshowclk();
PORTD.RD2=0; //OUTPUT
PORTD.RD3=0;
PORTD.RD4=1;
PORTD.RD5=0;
DELAY_MS(50);
// lcdshowclk();
PORTD.RD2=0; //OUTPUT
PORTD.RD3=1;
PORTD.RD4=0;
PORTD.RD5=0;
DELAY_MS(50);
// lcdshowclk();
PORTD.RD2=0; //OUTPUT
PORTD.RD3=0;
PORTD.RD4=0;
PORTD.RD5=1;
DELAY_MS(50);
break;
case'2': //anticlockwise
portd.rd0=0 ;
portd.rd1=1;
////////////
PORTD.RD2=0; //OUTPUT
PORTD.RD3=0;
PORTD.RD4=0;
PORTD.RD5=1;
DELAY_MS(50);
//lcdshowanticlk();
PORTD.RD2=0; //OUTPUT
PORTD.RD3=1;
PORTD.RD4=0;
PORTD.RD5=0;
DELAY_MS(50);
//lcdshowanticlk();
PORTD.RD2=0; //OUTPUT
PORTD.RD3=0;
PORTD.RD4=1;
PORTD.RD5=0;
DELAY_MS(50);
//lcdshowanticlk();
PORTD.RD2=1; //OUTPUT
PORTD.RD3=0;
PORTD.RD4=0;
PORTD.RD5=0;
DELAY_MS(50);
break;
}
}
} while (1);
}//~!
i had developed a code and the schematic for serial communication through pic18f452 ...using max 232...and rs232 cable...I have used PROTEUS ISIS to simulate the circuit....the code below will work when the either one of the two cases goes true....and and it is working but the problem i am facing is that in simulation when I execute the program and load the hex file in the controller in simulation its not working on the keys i defined for clockwise and ant- clockwise direction but it is moving clockwise when i press '2' and anti clockwise when i press '6'......and also if i change the characters for input they are not working for them......only '2',and '6' are working through numeric keypad....while between execution in ISIS the vitual terminal is also not showing the characters or any junk value.......I hope i defined my problem in suitable manner....please help...am in a great great trouble.........
bestregards
ALI SHAHEEN
****************the code***************
//the code is in mikroCv8.2
//using pic18f452
unsigned short i;
void main() {
portd=0;
trisd=0;
portb=0;
trisb=0;
// Initialize USART module (8 bit, 9600 baud rate, no parity bit..)
Usart_Init(9600);
do {
if (Usart_Data_Ready()) { // If data is received
i = Usart_Read(); // Read the received data
switch(i)
{
case'3': //clockwise
portd.rd0=1 ;
portd.rd1=0;
////////////
PORTD.RD2=1; //OUTPUT
PORTD.RD3=0;
PORTD.RD4=0;
PORTD.RD5=0;
DELAY_MS(50);
//lcdshowclk();
PORTD.RD2=0; //OUTPUT
PORTD.RD3=0;
PORTD.RD4=1;
PORTD.RD5=0;
DELAY_MS(50);
// lcdshowclk();
PORTD.RD2=0; //OUTPUT
PORTD.RD3=1;
PORTD.RD4=0;
PORTD.RD5=0;
DELAY_MS(50);
// lcdshowclk();
PORTD.RD2=0; //OUTPUT
PORTD.RD3=0;
PORTD.RD4=0;
PORTD.RD5=1;
DELAY_MS(50);
break;
case'2': //anticlockwise
portd.rd0=0 ;
portd.rd1=1;
////////////
PORTD.RD2=0; //OUTPUT
PORTD.RD3=0;
PORTD.RD4=0;
PORTD.RD5=1;
DELAY_MS(50);
//lcdshowanticlk();
PORTD.RD2=0; //OUTPUT
PORTD.RD3=1;
PORTD.RD4=0;
PORTD.RD5=0;
DELAY_MS(50);
//lcdshowanticlk();
PORTD.RD2=0; //OUTPUT
PORTD.RD3=0;
PORTD.RD4=1;
PORTD.RD5=0;
DELAY_MS(50);
//lcdshowanticlk();
PORTD.RD2=1; //OUTPUT
PORTD.RD3=0;
PORTD.RD4=0;
PORTD.RD5=0;
DELAY_MS(50);
break;
}
}
} while (1);
}//~!