Write a program that calculates PORTA 4 PORTB and sends ou

Write a program that calculates (PORTA + 4) * PORTB and sends out the result through PORTC and PORTD. Consider all the values unsigned.

Solution

1.   void main()
2.   {
3.   TRISA = 0xFF; //Set PORTA as Input
4.   TRISB = 0xFF; // Set PORTB as Input
5.   TRISC = 0xFF;
6.   TRISD = 0xFF;   
7.   PORTA = 0x00;
8.   PORTB = 0x00;
9.   PORTC = 0x00;
10.   PORTD = 0x00;
11.   CMCON = 0x07;
12.   ADCON1 = 0b10000110;
13.   // or
14.   // ADCON1 = 0b10000111;
15.   do
16.   {
17.  
18.   if(PORTA.F0 == 1) // If RA0 is Toggled
19.   {
20.   TRISC = 0x00; // Set PORTC as Output
21.   TRISD = 0x00; //Set PORTD as Output
22.   PORTB = 0xFF; // Toggle On
23.   Delay_ms(500);
24.   PORTB = 0x00; // Toggle OFF
25.   Delay_ms(500);
26.   TRISB = 0xFF;
27.   }
28.  
29.   if(PORTB.F0 == 1) // If RB0 is Toggled
30.   {
31.   TRISC = 0x00; // Set PORTC as Output
32. TRISD = 0x00; // Set PORTD as Output
33   PORTC = 0xFF; // Toggle On
34.   Delay_ms(500);
34.   PORTC = 0x00; // Toggle OFF
35.   Delay_ms(500);
36.   TRISC = 0xFF;
37.   }
38.  
39.   if(PORTC.F0 == 1) // If RC0 is Toggled
40.   {
41.   TRISD = 0x00; // Set PORTD as Output
42. TRISD = 0x00; // Set PORTD as Output
   PORTD = 0xFF; // Toggle On
43.   Delay_ms(500);
44.   PORTD = 0x00; // Toggle OFF
45.   Delay_ms(500);
46.   TRISD = 0xFF;
47.   }
48.  
49.   }while(1);
50.   }
51.   while(!RA0)
52.   {
53.   PORTB=0x01;
54.   __delay_ms(10000);
55.   }
56.  
57.   __delay_ms(40000);
58.  
59.  
60.   while(!RB0)
61.   {
62.   PORTB=0x02;
63.   __delay_ms(10000);
64.   }
60.   while(!RC0)
61.   {
62.   PORTD=((0x00)+4)*(0x00);
63.   __delay_ms(10000);
64.   }

Write a program that calculates (PORTA + 4) * PORTB and sends out the result through PORTC and PORTD. Consider all the values unsigned.Solution1. void main() 2.
Write a program that calculates (PORTA + 4) * PORTB and sends out the result through PORTC and PORTD. Consider all the values unsigned.Solution1. void main() 2.

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site