Need Hlp regarding the max232 program using hyper terminal

General discussion on mikroC.
Post Reply
Author
Message
imnewbie
Posts: 5
Joined: 16 Oct 2011 17:53

Need Hlp regarding the max232 program using hyper terminal

#1 Post by imnewbie » 07 Mar 2012 09:39

currently im writing a program which can use Hyper Terminal to control the variable that i set in the PIC16F877A. everything in my program works except the USART part.i cannot write anything once i connect the circuit to the computer. i have tried testing my circuit connection using the program USART test provided and it works. any expert here can correct my program (the Usart part)?PLs hlp me

//Final Year Project
signed int i;
signed int k;
signed int h;
signed int j;
unsigned short y;
unsigned short read;
unsigned short alphabet;
char pass[1];
char pazz[1];
char paqq[1];
void main() {
// pic16f887
// ANSEL = 0x00; //Digital I/O for PORTA
// ANSELH = 0x00; //Digital Input for PORTB

// pic16f877A
TRISB = 0; // PORTB is output
TRISD = 0xFF; //define as input
TRISA = 0; // PORTA is output
TRISC = 0;
PORTC = 0x0F;
Lcd_Init(&PORTB); // Initialize LCD connected to PORTB
Lcd_Cmd(Lcd_CLEAR); // Clear display
Lcd_Cmd(Lcd_CURSOR_OFF); // Turn cursor off

i=0;
k=0;
h=0;
lcd_out(1,1,"Password: ");
j=0;

PORTC.F3=1;


pass[0]= (i-((i/10)*10))+48;
Lcd_Out(1,14,pass);

pazz[0]= (k-((k/10)*10))+48;
Lcd_Out(1,15,pazz);

paqq[0]= (h-((h/10)*10))+48;
Lcd_Out(1,16,paqq);

PORTD.F6 = 0;

USART_Init(2400);

while(1)
{
if (USART_Data_Ready()) //USART setting
{read = Usart_read();
if (read == 'i')
alphabet ='i';
else if (read =='k')
alphabet ='k';
else if (read =='h')
alphabet ='h';

else if (read <'0');

else if (read >'9');

else if (alphabet =='i')
i = read-'0';
else if (alphabet =='k')
k = read-'0';
else if (alphabet =='h')
h = read-'0';

}

if (PORTD.F1 == 1) //button to set 1st digit of the password
{
if(i>9)
{
i=0;
}
i++; //to set each time press will +1
pass[0]= (i-((i/10)*10))+48;
Lcd_Out(1,14,pass); //out the password set
delay_ms(500); //to set the delay of the sensor

}

if (PORTD.F2 == 1) //button to set 1st digit of the password
{
if(k>9)
{
k=0;
}
k++; //to set each time press will +1
pazz[0]= (k-((k/10)*10))+48;
Lcd_Out(1,15,pazz); //out the password set
delay_ms(500); //to set the delay of the sensor
}

if (PORTD.F3 == 1) //button to set 1st digit of the password
{
if(h>9)
{
h=0;
}
h++; //to set each time press will +1
paqq[0]= (h-((h/10)*10))+48;
Lcd_Out(1,16,paqq); //out the password set
delay_ms(500); //to set the delay of the sensor
}

if(i!=9 || k!=2 || h!=5)
{
PORTC.F4=0;
PORTC.F3=1;
Lcd_Out(2,1,"Incorrect Pass");
}

else if(i==9 && k==2 && h==5) //setting the password
{
PORTC.F4=1;
PORTC.F3=0;
Lcd_Out(2,1,"ACCESS GRANTED");
delay_ms(5000);

i=0;
pass[0]= (i-((i/10)*10))+48;
Lcd_Out(1,14,pass);

k=0;
pazz[0]= (k-((k/10)*10))+48;
Lcd_Out(1,15,pazz);

h=0;
paqq[0]= (h-((h/10)*10))+48;
Lcd_Out(1,16,paqq);
}

if (PORTC.F3 == 1)
{
PORTC.F4=0;
}

if (PORTD.F6 == 1) //setting of the DCmotor turning clockwise
{
PORTC.F5 = 1;
PORTC.F2 = 0;
delay_ms(10000); //setting of the delay

if (PORTD.F6 == 0) //setting of the DCmotor turning anticlockwise
{
PORTC.F2 = 1;
PORTC.F5 = 0;
delay_ms(10000); //setting of the delay
PORTC.F6 = 0;
}
}
}
}

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: Need Hlp regarding the max232 program using hyper termin

#2 Post by filip » 08 Mar 2012 10:06

Hi,

Please, writing custom codes is a bit of the mikroElektronika Support scope, but I can give you a hint on this.
It is a good practice to read UART incoming data via interrupt and process the data using the state machine.

You can see this in the following example :
http://www.mikroe.com/eng/downloads/get ... s_v100.zip

In the GSM example an incoming data is received and then parsed in the interrupt routine.
According to the parsed data, different actions are performed, as you would do in your case.

Regards,
Filip.

imnewbie
Posts: 5
Joined: 16 Oct 2011 17:53

Re: Need Hlp regarding the max232 program using hyper termin

#3 Post by imnewbie » 08 Mar 2012 16:20

sir.i still dun understand.i just wan to know how to use usart to change the variable on my code. lets say i set i=0.the lcd will display 0. i wan hlp on how to use usart to change the i from 0 to another number. pls hlp me mr.filip or other pro.pls.

Post Reply

Return to “mikroC General”