You are on page 1of 5

NAME: Kshitij Shallesh Tater

REG NO: 21BEE0094

Code:
#include <reg51.h>

#define FREQ_CALCULATION_TIME 1000


#define CRYSTAL_FREQUENCY 11059200

void initTimer0() {
TMOD &= 0xF0;
TR0 = 0;
}

unsigned int measureFrequency() {


unsigned int count;
unsigned long frequency;

TR0 = 1;
count = 0;

while (TF0 == 0 && count < FREQ_CALCULATION_TIME) {


count++;
}

TR0 = 0;

frequency = (unsigned long)CRYSTAL_FREQUENCY / ((unsigned


long)count * 65536);

return (unsigned int)frequency;


}
void displayFrequency(unsigned int frequency) {
P1 = frequency & 0xFF;
P2 = (frequency >> 8) & 0xFF;
}

void main() {
unsigned int frequency;

initTimer0();

while (1) {
frequency = measureFrequency();
displayFrequency(frequency);
}
}

Code:
#include <reg51.h>

void initTimer0() {
TMOD &= 0xF0;
TMOD |= 0x02;
TH0 = 0x3C;
TL0 = 0xB0;
TR0 = 1;
}

void main() {
P1 = 0xFE;
initTimer0();

while(1) {

}
}

Code:
#include <reg51.h>

#define BAUD_RATE 2400


#define TIMER1_RELOAD_VALUE (65536 - (int)(256 - (1.0 *
(CRYSTAL_FREQUENCY / (12.0 * BAUD_RATE)))))

void initSerial() {
TMOD &= 0x0F;
TMOD |= 0x20;

TH1 = TL1 = TIMER1_RELOAD_VALUE;


TR1 = 1;

SCON = 0x50;
TI = 1;
}

void sendChar(char c) {
SBUF = c;
while (!TI);
TI = 0;
}

void sendString(char *str) {


while (*str) {
sendChar(*str++);
}
}

void main() {
P1 = 0xFF;
initSerial();
while(1) {
if (P1 & 0x01) {
sendString("TURNED-ON\r\n");
} else {
sendString("TURNED-OFF\r\n");
}
}
}

Code:
#include <reg51.h>

#define XTAL_FREQUENCY 11059200


#define TWO_MINUTES_DELAY (65536 - ((XTAL_FREQUENCY / 12)
* 120))

unsigned int counter = 0;

void initTimer1() {
TMOD &= 0x0F;
TMOD |= 0x10;

TH1 = TL1 = TWO_MINUTES_DELAY;


TR1 = 1;
}

void main() {
initTimer1();

while(1) {
if (TF1) {
TR1 = 0;
counter = 0;
TH1 = TL1 = TWO_MINUTES_DELAY;
TF1 = 0;
TR1 = 1;
}

if (/* condition for person entering hall */) {


counter++;
}
}
}

You might also like