Maker Pro
Maker Pro

program a router in microCfor PIC 16f887

zemzela

Dec 19, 2011
7
Joined
Dec 19, 2011
Messages
7
program the PIC to work as a Super Router, and reading the serial
port frame, forwards them to the standard, or rejected. The next message
format:

1. Destination MAC, 6 bytes fixed - variable value for each frame
2. TTL, 1 byte fixed - variable value for each frame
3.Length,1 byte fixed - variable value for each frame
4. Data, [1, 16] bytes - variable value, variable length for each frame
5. Error Code, 1 byte fixed - sum of all units in the field 1-4

And process the PIC as follows:
First Checking the MAC address.
- If it is rejected and the LCD display reads in two lines - "Receive
frame which is not for me ".
- If it is addressed, go to step 2

Second Checking the Error Code.
- If the frame is error, rejecting the LCD screen and write in two rows -
"Receive frame which is error".
- If the frame is not an error, go to step 3

Third Check the TTL.
- If the TTL is 0, the frame is discarded and the LCD display reads in two rows -
"Receive frame TTL = 0".
- If TTL> 0, go to step 4.

4th Creating a framework for sending.
- In the Dest. MAC value is entered as DestMac own arbitrary will
create it as a variable
- TTL field is reduced by 1 from the received frame
- Length field remains the same
- Data remains the same field
- Calculate new value for the Error Code field

After creating the frame, it sends the serial port, and write the first row of the LCD
- "Receive frame:", second row area Data

After sending, wait for a new framework. Assume that in the meantime not to arrive
new framework.

Any ideas how to solve this problem, It is very important for me, please help me....
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,505
Joined
Jan 21, 2010
Messages
25,505
Is this an assignment?
 

zemzela

Dec 19, 2011
7
Joined
Dec 19, 2011
Messages
7
I should make a project, and I need help about the first part which is about destinationmac?
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,505
Joined
Jan 21, 2010
Messages
25,505
I think we need a larger picture of what's going on here.

What are you doing?
 

zemzela

Dec 19, 2011
7
Joined
Dec 19, 2011
Messages
7
I don't understand the task, and I need help to understand how to solve the task, if you know help me?
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,505
Joined
Jan 21, 2010
Messages
25,505
The wording of the problem and your reluctance to tell us more tell me that this is your homework.

So it's off to the homework section for this.

Perhaps now you can tell us what class you're doing and what parts you do understand and what parts you don't
 

zemzela

Dec 19, 2011
7
Joined
Dec 19, 2011
Messages
7
send on serial port first num: dispaly on LCD Num1: 9
second num: Num2: 8
operation: (+,-,/,*): oper: * Rez: 72
Send byte for first num and second num, and send char for operation

the problem is that when I try send byte, it says Enter byte value to be sent to UART receiver[0-255]
that is why I couldn't send number larger than 255.

I tried to send string (200*2) but it couldn't calculate the product of this numbers. UART1_Read function return int type in my code, but now i think should return string


Do you have any ideas how to solve this? Here is my code:

/================= konfigure LCD display
// port for data PORTB
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
//================================================== =======

//===========variables
char operation;
int nbr1=0,nbr2=0,result=0,rest=0;
char txt[16],br[7];
//================================================== =======

//======== delete empty spaces
void empty_spaces(char array[]){
int j=0,i=0,n=0;
n=strlen(array);
while(i<n){
if(array==' '){
j=i;
while(j<n){
array[j]=array[j+1];
++j;
}
--n;
}else
++i;
}
if(n>15)
n=15;
array[n]='\0';
}
//================================================== =======

//========function back int from the imported char

int back_char(char operation ){
if(operation=='+')
return 1;
if(operation=='-')
return 2;
if(operation=='*')
return 3;
if(operation=='/')
return 4;
if(operation=='%')
return 5;
return 0;
}
//================================================== =======

//============= init lcd display and serial port
void inicijalizacija(){
PORTB = 0xFF;
TRISB = 0x00;
ANSEL = 0x00;
ANSELH = 0x00;
C1ON_bit = 0;
C2ON_bit = 0;
UART1_Init(9600);
Delay_ms(100);
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
}
//================================================== =======

void main(){
inicijalizacija();
//============= enter first number
UART1_Write_Text("first num:");
UART1_Write(10);
UART1_Write(13);
do{
}while(!UART1_Data_Ready());
nbr1=UART1_Read();
IntToStr(nbr1,br);
strcpy(txt,"Num1:");
strcat(txt,br);
empty_spaces(txt);
Lcd_Out(1,1,txt);
Delay_ms(1);


//=============enter second number
UART1_Write_Text("second num:");
UART1_Write(10);
UART1_Write(13);
do{
}while(!UART1_Data_Ready());
nbr2=UART1_Read();
IntToStr(nbr2,br);
strcpy(txt,"Num2:");
strcat(txt,br);
empty_spaces(txt);
Lcd_Out(1,10,txt);
Delay_ms(1);
//================================================== ============

//enter operation

UART1_Write_Text("operation(+,-,/,*,%):");
UART1_Write(10);
UART1_Write(13);
do{
}while(!UART1_Data_Ready());
operation=UART1_Read();
strcpy(txt,"oper:");
switch(back_char(operation)){
case 0: strcat(txt," ");break;
case 1:
strcat(txt,"+");
result=nbr1+nbr2;
break;
case 2:
strcat(txt,"-");
result=nbr1-nbr2;
break;
case 3:
strcat(txt,"*");
result=nbr1*nbr2;
if(nbr2!=result/nbr1)
operation=' ';
break;
case 4:
strcat(txt,"/");
if(nbr2==0)
operation=' ';
else{
result=nbr1/nbr2;
rest=nbr1%nbr2;
}
break;
case 5:
strcat(txt,"%");
if(nbr2==0)
operation=' ';
else
result=nbr1%nbr2;
break;
}
empty_spaces(txt);
Lcd_Out(2,1,txt);
Delay_ms(1);
//================================================== ============

//============= Print result

if(back_char(operation)!=0){
IntToStr(result,br);
strcpy(txt,"Rez:");
strcat(txt,br);
empty_spaces(txt);
if(back_char(operation)!=4)
Lcd_Out(2,7,txt);
else{ // Dokolku vrednosta od funkcijata vrati_znak(operacija) e 4
IntToStr(rest,br); // se raboti za delenje
empty_spaces(br);
strcat(txt,"~");
strcat(txt,br);
Lcd_Out(2,5,txt);
}
}else
Lcd_Out(2,7,"error!");
Delay_ms(1);
//================================================== ============
}
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,505
Joined
Jan 21, 2010
Messages
25,505
Is this the same problem?

8 bits can only encode 256 values (0 to 255 if unsigned).

16 bits can encode 65536 values (0 to 65535 if unsigned).

Are you sure you want to send raw binary values to a LCD display? Surely you need to do a binary to decimal conversion, then convert each digit to the appropriate character and send that.
 

zemzela

Dec 19, 2011
7
Joined
Dec 19, 2011
Messages
7
I asked how to do this?

send on serial port first num: dispaly on LCD Num1: 9
second num: Num2: 8
operation: (+,-,/,*): oper: * Rez: 72
Send byte for first num and second num, and send char for operation

the problem is that when I try send byte, it says Enter byte value to be sent to UART receiver[0-255]
that is why I couldn't send number larger than 255.

I tried to send string (200*2) but it couldn't calculate the product of this numbers. UART1_Read function return int type in my code, but now i think should return string
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,505
Joined
Jan 21, 2010
Messages
25,505
I tried to send string (200*2) but it couldn't calculate the product of this numbers. UART1_Read function return int type in my code, but now i think should return string

Yes, I agree. It's exactly what I said.

If you multiply two 8 bit numbers, your result may be up to 16 bits.
 

zemzela

Dec 19, 2011
7
Joined
Dec 19, 2011
Messages
7
And do you have any idea how to solve it? Or tell me how to find some useful links where I could find how to solve this?
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,505
Joined
Jan 21, 2010
Messages
25,505
Yeah, read what I said.

To me it looks like you're reading characters then trying to add/subtract/multiply them.

Are you doing a string to integer conversion first?

If so, where in your code is it being done?

What is the size of your integer variables? Is it large enough to accommodate the expected range of values?

Do you convert the integer (or float?) value back to string again before you output it?

If so, where?
 

zemzela

Dec 19, 2011
7
Joined
Dec 19, 2011
Messages
7
I don' t know how to solve my task. Please suggested me useful links to learn how it works serial port in microC for Pic 8086? It is very important for me, to learn this.
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,505
Joined
Jan 21, 2010
Messages
25,505
I've always found this the best.

Unfortunately it also requires that you are able to describe things better than "I don't know", but best of luck.
 
Top