Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction To Data Mining

Authors: Pang Ning Tan, Michael Steinbach, Vipin Kumar

1st Edition

321321367, 978-0321321367

More Books

Students also viewed these Databases questions