0% found this document useful (0 votes)
48 views

Hcs12 Code

The document contains C code for controlling LEDs on a microcontroller. It defines functions for initializing port B of the microcontroller as an output and for delaying execution. The main function sets port B to output, turns off all LEDs initially, and then enters a forever loop that blinks the LEDs in different patterns by writing values to port B and delaying between each write.

Uploaded by

darkavengerpark
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

Hcs12 Code

The document contains C code for controlling LEDs on a microcontroller. It defines functions for initializing port B of the microcontroller as an output and for delaying execution. The main function sets port B to output, turns off all LEDs initially, and then enters a forever loop that blinks the LEDs in different patterns by writing values to port B and delaying between each write.

Uploaded by

darkavengerpark
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

1

MAIN.C

#include "main.h"

void delay(unsigned int n);

void main()

//unsigned char mask;

// Make Port B to output

Regs.ddrb.byte = 0xFF; // Set port B to output

// Turn off LED

Regs.portb.byte = 0xFF; // Make all port B to 1

for (;;) {

Regs.portb.byte = 0b00111100;

delay(5);

Regs.portb.byte = 0b11000011;

delay(5);

}
}

// ÀÏÁ¤ÇÑ ½Ã°£À» Áö¿¬½ÃŰ´Â ÇÔ¼ö

void delay(unsigned int n)

unsigned int i;

while (n > 0) {

for (i=1; i != 0; i++); // ¾Æ¹«°Íµµ ÇÏÁö ¾ÊÀ¸¸é¼- ½Ã°£ Áö¿¬

n--;

MAIN.H

#ifndef MAIN_H /*prevent duplicated includes*/

#define MAIN_H

#include "projectglobals.h"

#endif /*MAIN_H*/
2

MAIN.C

#include "main.h"

void delay(unsigned int n);

void main()

//unsigned char mask;

// Make Port B to output

Regs.ddrb.byte = 0xFF; // Set port B to output

// Turn off LED

Regs.portb.byte = 0xFF; // Make all port B to 1

for (;;) {

Regs.portb.byte = 0x00;

delay(5);

Regs.portb.byte = 0x18;

delay(5);

Regs.portb.byte = 0x3C;
delay(5);

Regs.portb.byte = 0x7E;

delay(5);

Regs.portb.byte = 0xFF;

delay(5);

Regs.portb.byte = 0x7E;

delay(5);

Regs.portb.byte = 0x3C;

delay(5);

Regs.portb.byte = 0x18;

delay(5);

// ÀÏÁ¤ÇÑ ½Ã°£À» Áö¿¬½ÃŰ´Â ÇÔ¼ö


void delay(unsigned int n)

unsigned int i;

while (n > 0) {

for (i=1; i != 0; i++); // ¾Æ¹«°Íµµ ÇÏÁö ¾ÊÀ¸¸é¼- ½Ã°£ Áö¿¬

n--;

MAIN.H

#ifndef MAIN_H /*prevent duplicated includes*/

#define MAIN_H

#include "projectglobals.h"

#endif /*MAIN_H*/

MAIN.C

#include "main.h"

void delay(unsigned int n);

void main()
{

//unsigned char mask;

// Make Port B to output

Regs.ddrb.byte = 0xFF; // Set port B to output

// Turn off LED

Regs.portb.byte = 0xFF; // Make all port B to 1

for (;;) {

Regs.portb.byte = 0x7E;

delay(5);

Regs.portb.byte = 0xBD;

delay(5);

Regs.portb.byte = 0xDB;

delay(5);

Regs.portb.byte = 0xE7;

delay(5);

Regs.portb.byte = 0xFF;
delay(5);

Regs.portb.byte = 0xDB;

delay(5);

Regs.portb.byte = 0xBD;

delay(5);

Regs.portb.byte = 0x7E;

delay(5);

// ÀÏÁ¤ÇÑ ½Ã°£À» Áö¿¬½ÃŰ´Â ÇÔ¼ö

void delay(unsigned int n)

unsigned int i;

while (n > 0) {

for (i=1; i != 0; i++); // ¾Æ¹«°Íµµ ÇÏÁö ¾ÊÀ¸¸é¼- ½Ã°£ Áö¿¬

n--;

}
MAIN.H

#ifndef MAIN_H /*prevent duplicated includes*/

#define MAIN_H

#include "projectglobals.h"

#endif /*MAIN_H*/

You might also like