Answered step by step
Verified Expert Solution
Question
1 Approved Answer
need good explanation can you tell me the logic of this code step by step please 4. Software Development (SLO2) (20p) Throw the Dice program
need good explanation can you tell me the logic of this code step by step please
4. Software Development (SLO2) (20p) Throw the Dice program - Explanation: To throw the dice, user will press and release the S1 button. Pressing S1 button starts counting (increase) the diceval from 1 to 6 very fast so nobody can perceive its value on LEDs. When S1 is released, counting stops and diceval value is written to PortD in binary format (Hence the Dice Value is displayed on LEDs). Please note that diceval can only be between 1 to 6. (S1 button is connected to PORTB 0 and LEDs are connected to PORTD of 16F877A MCU.) Please write the program in C language (main fuction will be enough. Please do the necessary initializations in main function. Use the data sheet explanations below). Answer: void main(void) \{ \#define S1 PORTB \& 0x 1 int diceval =1;/ can be initialized with any value between 1 to 6 TRISD =0x00;// portd is set as output TRISB=0xff ; // portb will be input. This line is optional, because, in reset PORTB is // already configured as input PORTD = diceval; while (1) \{ while (S1) \{ diceval++ if ( diceval >6) diceval =1;// diceval has to be between 1 to 6 PORTD = diceval; \} \} \}Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started