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

Repeat Exercise 3 using the C language printing the value of TMR0 on the 7-segme

ID: 3576831 • Letter: R

Question

Repeat Exercise 3 using the C language printing the value of TMR0 on the 7-segment

display instead of the LCD.

Build Version Control Fir EQU 0x0C Warningl2U/JCAUSERS Warning 2071 CAUSERS ORG 0x000 Warning[207 CUSERS goto main Warning[2071 CAUSERS ORG 0x004 Warningl207 CAUSERS ret Warning[207] CAUSERS main Warning[207]CAUSERS BSF STATUS, RPO Warning[207] CAUSER BSF TRISA, 4 Warning[207] CAUSERS BCF TRISA, 0 Warningl2071 CAUSERS TRISA, 1 Warning[2071 CAUSERS CLRF TRISB Warning[207]CAUSERS BSF OPTION REG arning[203] CAUSERS BSF OPTION REG Warning[2071 CAUSER BSF OPTION REG, 3 Warning[2071 CAUSERS BCF OPTION REG, 2 BCF OPTION REG. 1 Warning[207] CAUSERS Message[302] CAUSEF BCF OPTION REG, 0 BCF STATUS, RPO Message 3021 CAUSER CALL 12C INIT Initialize Message[302]CAUSEF CALL LCD INIT Initialize Message[302] CAUSEF MOVLW 0x00 Message[302]CAUSER MOVIE lcdline Start at 1 302] CAUSEF MOVLW D'0 Message MOVINF led column Start a1 Message 302] CAUSEF Executing: "CAProgram CALL LCD SET CURSOR plac MPLINK 4.49, Linke CLRF TMRO Device Database Ve LOOP MOVE TMRO, 0 Copyright (c) 199 MOVIE PORTB Errors CALL BIN2BCD CALL DisplayValue Loaded CAUsersS000 GOTO LOOP include "DELAY .inc" Debug build of project de "Led. inc" Language tool versions include 12C. inc Preprocessor symbo Thu Dec 01 08:58:44 20 END

Explanation / Answer

The below code is the code to display on 7-segment in C lnaguage.

WinAVR Code to display 0-9 or 0-F to 7-segment display. PIN wiring is

Pin Segment

7 g

6 b

5 d

4 f

3 DP

2 e

1 a

0 c

// clock speed for delay

#define F_CPU 1000000UL // New AVR devices are at 1MHz Internal clock

// STK200 board has 8MHz cystal

#include <avr/io.h>

#include <util/delay.h>

//Configurations

//**************

// Change constant here to change port used by 7-segment

#define PORT_7_SEGMENT PORTB

#define DDR_7_SEGMENT DDRB

void SevenSegment(uint8_t count,uint8_t dp,unit8_t dec_hex)

{

// This function shows value of count on display the decimal point is displayed if dp=1

if(count <dec_hex)

{

switch (count)

{

case 0:

PORT_7_SEGMENT=0b10001000;

break;

case 1:

PORT_7_SEGMENT=0b10111110;

break;

case 2:

PORT_7_SEGMENT=0b00011001;

break;

case 3:

PORT_7_SEGMENT=0b00011100;

break;

case 4:

PORT_7_SEGMENT=0b00101110;

break;

case 5:

PORT_7_SEGMENT=0b01001100;

break;

case 6:

PORT_7_SEGMENT=0b01001000;

break;

case 7:

PORT_7_SEGMENT=0b10111100;

break;

case 8:

PORT_7_SEGMENT=0b00001000;

break;

case 9:

PORT_7_SEGMENT=0b00001100;

break;

//hex only

case 10:

PORT_7_SEGMENT=0b00101000; //A

break;

case 11:

PORT_7_SEGMENT=0b01001010; //b

break;

case 12:

PORT_7_SEGMENT=0b11001001; //C

break;

case 13:

PORT_7_SEGMENT=0b00011010; //d

break;

case 14:

PORT_7_SEGMENT=0b01001001; //E

break;

case 15:

PORT_7_SEGMENT=0b01101001; //F

break;

}

if(dp)

{

//if decimal point should be displayed make DP bit Low

PORT_7_SEGMENT&=0b11110111;

}

}

else

{

//This symbol on display shows that count was greater than 9 or 15

//so display can't handle it

PORT_7_SEGMENT=0b11011111;

}

}

int main()

{

//Setup

DDR_7_SEGMENT=0xFF; //All output

PORT_7_SEGMENT=0xFF; //All segments off

uint8_t count=0;

uint8_t dec_hex=16; //change to 10 for decimal

while(1) //loop forever

{

SevenSegment(count,0, dec_hex);

count++;

if(count==dec_hex)

{

count=0;

}

_delay_ms(1000);

}

}