You are on page 1of 5

FULL LAB REPORT EXP.

5
Copy & Paste :
void Display_Freq(unsigned int value2write)
{
PORTD = value2write; //Display the current count value at PORTD
}
void main()
{
ADCON1 = 0x0F; // Configure all ports with analog function as digital
CMCON = 7; // Disable comparators
TRISD = 0x00; // PORTD O/P
TRISA = 0b00010000; // RA4/T0CKI input
T0CON.TMR0ON = 1; // Turn Timer 0 ON
T0CON.T0CS = 1; //Transition on T0CKI pin (RA4) - configure TMRO as counter
T0CON.T0SE = 0; //Increment on falling edge transition on T0CKI pin (RA4)
TMR0L=0; // Initialize TMR0L reg to 0
PORTD=0; // Turn PORTD off initially
do
{
Display_Freq(TMR0L); //Pass the current value in TMR0L reg to Display_Freq function
} while(1); // Infinite loop
}//End of void main()

Observation:
The led are lightning on according to the arrangement of the binary numbers, with every one
press to the switch it count the next number

MIKRO C:
void Display_Freq

(unsigned int value2write)

{
PORTD = value2write;

//Display the current count value at PORTD

}
void main()
{
ADCON1 = 0x0F;

// Configure all ports with analog function as digital

CMCON = 7;

// Disable comparators

TRISD = 0x00;

// PORTD O/P

TRISA = 0b00010000;

// RA4/T0CKI input

TRISB = 0B00000001;

T0CON.TMR0ON = 1;

// Turn Timer 0 ON

T0CON.T0CS = 1;

//Transition on T0CKI pin (RA4) - configure TMRO as counter

T0CON.T0SE = 0;

//Increment on falling edge transition on T0CKI pin (RA4)

TMR0L=0;

// Initialize TMR0L reg to 0

PORTD=0;

// Turn PORTD off initially

do
{
if(button(&PORTB,0,1,0))
{TMR0L=0;}

//Pass the current value in TMR0L reg to Display_Freq function

else if(TMR0L>9)
{TMR0L=0;}
else
{Display_Freq(TMR0L);}
} while(1);

// Infinite loop

//End of void main()

MPLAB:
#include<p18F4550.inc>
org 0x00
goto start
org 0x08
retfie
org 0x18
retfie
;main program
start
movlw 0x0F
movwf ADCON1

movlw 0x07
movwf CMCON
CLRF TRISD
MOVLW 0xFF
MOVFF WREG,PORTB
MOVFF WREG,PORTA
MOVLW 0xA0
MOVFF WREG,T0CON
CLRF TMR0L
CLRF PORTD
AGAIN
MOVFF

TMR0L,PORTD

BTFSC

PORTB,0

BRA LOOP
BRA RES
LOOP
MOVLW

0X0A;

CPFSEQ

TMR0L,A;

BRA

AGAIN

BRA

RES2

RES
CLRF

TMR0L,A

BRA

LOOP

RES2
CLRF

TMR0L,A

BRA

LOOP

END

Observation:
The seven segment display count the number start from zero to 9 when press first switch.
If reset button is being press the number in seven segment display will return to zero also when
it count from zero to nine.

You might also like