Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

BCD Decoder a. Determine which registers and their configuration values to setup

ID: 3771570 • Letter: B

Question

BCD Decoder a. Determine which registers and their configuration values to setup the inputs and output ports for the control circuit shown in figure 1 using the Zero Gecko MCU. b. Write the C program using the SiLab Peripheral library (emlib) functions to configure the microcontroller to perform the following task: A BCD 7 seg decoder is a device that converts a 4-bit binary code into a 7 segment representation of the decimal number representation. Your program will monitor the START switch, when a pressed the MCU will driver the 4-bit BCD input via (PA0-PA3) pins, it will count from 0 to 9 and repeat at a 1 sec rate. During the counting processing, The START button can be pressed, if a pressed is detected the count will stop/freeze, if the START button is pressed again the count will reset to 0, and the count will restart if the START button is pressed again. Show the State diagram of your algorithm. You must use a general purpose timer (no SysTick timer) Show your C code only, no SiLab project is required, but you may test your program using the evaluation board and debugger. Name: _________________________________________________ Date: ___________ 2 Figure 1 E

Explanation / Answer

unsigned int cnt ,brk;char led [3]; unsigned int rem ; void converter (unsigned int z); void scanled (void); void main() { OPTION_REG = 0x80; // pull up resistors // PORTA = 0; // clear porta (make sure both displays are off) TRISA = 255; // designate porta pins as output PORTD = 0; // clear portb (make sure LEDs are off) TRISD = 0; // designate portb pins as input ADCON1 = 0x80; // Configure analog inputs and Vref while(1) cnt=ADC_Read(2); cnt=cnt*5; converter(cnt); scanled(); } } void converter(unsigned int z) { led[0] = z/1000; rem = z%1000 ; led[1] = rem/100; rem = rem%100 ; led[2] = rem/10; led[3] = rem%10; } void scanled(void){ unsigned char i; for(i=0;i<4;i++) { portd = i; portd = led[i]; delay_ms(10); }