SE-CLOCK-UNI

SC-CLOCK-UNI Á¶¸³ Å°Æ®´Â 4 °¡ÁöÀÇ ±â´ÉÀ» °¡Áö°í ÀÖ½À´Ï´Ù.. 

1: 12½Ã°£ ÃÊ ´ÜÀ§ Ç¥½Ã ½Ã°è
2: 99ºÐ±îÁö ÃøÁ¤µÇ´Â 1/100 ÃÊ ´ÜÀ§ ½ºÅé¿öÄ¡ ŸÀ̸Ó
3: ÆÞ½º ¾÷/´Ù¿î Ä«¿îÅÍ
4: ¿£ÄÚ´õ AB »ó ½ÅÈ£ Ä«¿îÅÍ

Àü¿ø °ø±Þ ÈÄ J1, J2 ÀÇ Á¡ÆÛ ÇÉ »óÅ¿¡ µû¶ó 4 °¡Áö Áß
1 °¡ÁöÀÇ ¸ðµå·Î µ¿ÀÛÇÕ´Ï´Ù.

¼Ò½º¿Í ȸ·Îµµ¸¦ ÀÚ¼¼ÇÏ°Ô °ø°³ÇÏ¿© 8051ÇÁ·Î¼¼¼­¿Í C ÇÁ·Î±×·¥À»
½±°Ô ¹è¿ï ¼ö ÀÖ´Â KIT ÀÔ´Ï´Ù.

9V °ÇÀüÁö¸¦ »ç¿ëÇÒ ¼ö ÀÖµµ·Ï ÀüÁö½º³ÀÀÌ Æ÷ÇԵǾî ÀÖ½À´Ï´Ù.

Crossware 8051 C ÄÄÆÄÀÏ·¯ µ¥¸ð¹öÁ¯

Crossware 8051 C ÄÄÆÄÀÏ·¯ Çѱ۸Ŵº¾ó


*** CPU ¿¡ HEX ÆÄÀÏÀÌ ¶óÀÌÆõǾî ÀÖ½À´Ï´Ù. ***


*** CPU ¿¡ HEX ÆÄÀÏÀÌ ¶óÀÌÆõǾî ÀÖ½À´Ï´Ù. ***


KIT ¿¡ ¿£ÄÚ´õ´Â Æ÷ÇÔµÇÁö ¾Ê½À´Ï´Ù.


*** CPU ¿¡ HEX ÆÄÀÏÀÌ ¶óÀÌÆõǾî ÀÖ½À´Ï´Ù. ***


*** CPU ¿¡ HEX ÆÄÀÏÀÌ ¶óÀÌÆõǾî ÀÖ½À´Ï´Ù. ***


*** CPU ¿¡ HEX ÆÄÀÏÀÌ ¶óÀÌÆõǾî ÀÖ½À´Ï´Ù. ***


*** CPU ¿¡ HEX ÆÄÀÏÀÌ ¶óÀÌÆõǾî ÀÖ½À´Ï´Ù. ***

³ë¶õ»ö: 9V, »¡°£»ö: 5V, Çϴûö: 0V


*** CPU ¿¡ HEX ÆÄÀÏÀÌ ¶óÀÌÆõǾî ÀÖ½À´Ï´Ù. ***

/////////////////////////////////////////////////////////////
//
// SE-CLOCK-UNI
//
// Clock / Timer / Pulse Counter / Quadrature Counter
//
// SAMPLE Electronics co. 
// TEL: +82-2-701-8051 FAX: +82-2-701-8058
// C-18 P1-Fl, Main-Bd. ET-Land 
// 16-9 Hangangno-3ga Yongsan-gu
// Seoul 140-879 South KOREA
// Email: sample@korea.com
// Web: HTTP://WWW.SAMPLE.CO.KR
//
// Programmed by Junghoon Kim
// Programmed on 7. DEC. 2005
//
// Crossware Embedded Development Studio V 3.3.1.2
//
/////////////////////////////////////////////////////////////
#include <sfr.h> // 8051 ÀÇ SFR ÀÌ Á¤ÀÇµÈ ÆÄÀÏ
#include <os.h> // 8051 ÀÇ ÀÎÅÍ·´Æ® ¹øÈ£ Á¤ÀÇµÈ ÆÄÀÏ 
/////////////////////////////////////////////////////////////
_sfrbit Set_alarm = _p3^2; // Clock 
_sfrbit Set_save = _p3^3; // Clock
_sfrbit Set_hour = _p3^4; // Clock
_sfrbit Set_minute = _p3^5; // Clock
//
_sfrbit Timer_start = _p3^4; // Timer / Stop Watch 
_sfrbit Timer_stop = _p3^5; // Timer / Stop Watch
//
_sfrbit Sig_z = _p3^3; // Quadrature Counter Clear
_sfrbit Sig_a = _p3^4; // Quadrature Counter A Input
_sfrbit Sig_b = _p3^5; // Quadrature Counter B Input
//
_sfrbit pulse_in = _p3^2; // Pulse Counter Input INT0 Pin
_sfrbit direction = _p3^4; // Pulse Counter Direction
_sfrbit clear = _p3^5; // Pulse Counter Clear
//
_sfrbit Buzer = _p3^6; // Clock / Timer
_sfrbit Minus = _p3^7; // Quadrature Counter / Pulse Counter
/////////////////////////////////////////////////////////////
unsigned char iclock; // Clock / Timer
unsigned char cent; // Clock / Timer
//
unsigned char previous_state; // Quadrature Counter 
int counter, qabcounter; // Quadrature Counter / Pulse Counter
//
_bit timer_run; // Timer
_bit move_enable; // Quadrature Counter / Pulse Counter
/////////////////////////////////////////////////////////////
void _interrupt IVN_INTERRUPT0 external_int0() { // Pulse Counter

if (direction == 1) {
counter++;
} else {
counter--;
}
if (move_enable) {
qabcounter = counter;
}
}
/////////////////////////////////////////////////////////////
void _interrupt IVN_TIMER0 time_base() { // Clock, Timer

iclock++;
if (iclock > 39) { // 250 nS x 40 = 10 mS
iclock = 0;
cent++; // 1/100 S (10 mS)
}
}
/////////////////////////////////////////////////////////////
void _interrupt IVN_TIMER1 quad_input() { // Quadrature Counter
//
#define QS0 0x00 // 00 00 S0 S0+ . ¹«º¯È­
#define QS1 0x01 // 00 01 S0 S1+ + Áõ°¡
#define QS3 0x03 // 00 11 S0 S2+ ?
#define QS2 0x02 // 00 10 S0 S3+ - °¨¼Ò

#define QS4 0x04 // 01 00 S1 S0+ - °¨¼Ò
#define QS5 0x05 // 01 01 S1 S1+ . ¹«º¯È­
#define QS7 0x07 // 01 11 S1 S2+ + Áõ°¡
#define QS6 0x06 // 01 10 S1 S3+ ?

#define QSC 0x0C // 11 00 S2 S0+ ?
#define QSD 0x0D // 11 01 S2 S1+ - °¨¼Ò
#define QSF 0x0F // 11 11 S2 S2+ . ¹«º¯È­
#define QSE 0x0E // 11 10 S2 S3+ + Áõ°¡

#define QS8 0x08 // 10 00 S3 S0+ + Áõ°¡
#define QS9 0x09 // 10 01 S3 S1+ ?
#define QSB 0x0B // 10 11 S3 S2+ - °¨¼Ò
#define QSA 0x0A // 10 10 S3 S3+ . ¹«º¯È­
//
unsigned char current_state, t;
_tl1 = 0xB5; _th1 = 0xFF; // Timer Set 
// FFCE:50uS FFB5:75uS FF9C:100uS (12MHz CLK)
t = _p3;
current_state = (t >> 4) & 0x03;
t = (previous_state << 2) | current_state;
previous_state = current_state;

switch(t) {
case QS1: counter++; break; // Áõ°¡
case QS2: counter--; break; // °¨¼Ò
case QS4: counter--; break; // °¨¼Ò
case QS7: counter++; break; // Áõ°¡
case QSD: counter--; break; // °¨¼Ò
case QSE: counter++; break; // Áõ°¡
case QS8: counter++; break; // Áõ°¡
case QSB: counter--; break; // °¨¼Ò
}

if (Sig_z == 0) { 
counter = 0;

if (move_enable) {
qabcounter = counter;
}
}
/////////////////////////////////////////////////////////////
void fnd_display(unsigned char a, unsigned char b, unsigned char c) {
/***********************************************************
* FND 1 2 3 4 5 6 *
* +---+ +---+ +---+ +---+ +---+ +---+ *
* | | | | | | | | | | | | *
* +---+ +---+ +---+ +---+ +---+ +---+ *
* | | | | | | | | | | | | *
* +---+ +---+ +---+ +---+ +---+ +---+ *
* a b c *
* *
* 8 ºñÆ® ¹«ºÎÈ£ Á¤¼ö a,b,c ¸¦ ÀÔ·ÂÀ¸·Î ÇÏ¿© a ´Â FND1, *
* FND2 b ´Â FND3, FND4 ±×¸®°í c ´Â FND5, FND6 ¿¡ *
* ¼ýÀÚ¸¦ Ç¥½ÃÇÕ´Ï´Ù. a,b,c ´Â 0 ~ 99 ±îÁöÀÇ ¹üÀ§ ÀÔ´Ï´Ù. *
* *
***********************************************************/
unsigned char u,v,m,t,x,y,z;

u = a / 10; // FND 6 Port2
v = a % 10; // FND 5
u = u << 4 ;

x = u | v;

u = b / 10; // FND 4 Port0
v = b % 10; // FND 3
u = u << 4;

y = u | v;

u = c / 10; // FND 2 Port1
v = c % 10; // FND 1
u = u << 4;

z = u | v;

t = z & 0xF0; // »óÀ§ FNDÀÇ 0 À» ºí·©Å© 󸮠
if (t == 0) { 
z = z | 0xF0;
t = z & 0x0F;
if (t == 0) {
z = 0xFF;
t = y & 0xF0;
if (t == 0) {
y = y | 0xF0;
t = y & 0x0F;
if (t == 0) {
y = 0xFF;
t = x & 0xF0;
if (t == 0) {
x = x | 0xF0;
}
}
}
}
}

_p2 = x;
_p0 = y;
_p1 = z;

}
/////////////////////////////////////////////////////////////
void delay() {
/***********************************************************
* Delay *
* *
* for ¹®À» ÀÌ¿ëÇÑ °£´ÜÇÑ µô·¹ÀÌ ·çƾÀÔ´Ï´Ù. *
* *
***********************************************************/
unsigned int i;
for (i = 0; i < 10000; i++) ;
}
/////////////////////////////////////////////////////////////
void quadrature_counter() { // AB(quadrature) ½ÅÈ£ Ä«¿îÅÍ 
/***********************************************************
* Quadrature Counter *
* *
* ÀÌ ÇÁ·Î±×·¥Àº ·ÎÅ͸®/¸®´Ï¾î ¿£ÄÚ´õ¿¡¼­ Ãâ·ÂµÇ´Â *
* A/B »ó ½ÅÈ£¸¦ Ä«¿îÆ®ÇÏ¿© µð½ºÇÁ·¹ÀÌ ÇÏ´Â *
* ¿¹¸¦ º¸ÀÎ °ÍÀÔ´Ï´Ù. *
* A/B »ó ½ÅÈ£´Â ¼ÒÇÁÆ®¿þ¾î¿¡ ÀÇÇÏ¿© 4 ü¹è ¹æ½ÄÀ¸·Î *
* ºÐÇØÇÏ¿© ÁøÇà ¹æÇâ°ú Ä«¿îÆ® ¾çÀ» °è»êÇÕ´Ï´Ù. *
* A/B »ó ½ÅÈ£´Â Timer1 À» Mode 1 À¸·Î ¼³Á¤ÇÏ¿© *
* 75uS ÁÖ±â·Î »ùÇøµÇÕ´Ï´Ù. *
* ŸÀÌ¸Ó ÀÎÅÍ·´Æ®°¡ ¹ß»ýÇÒ ¶§¸¶´Ù Áֱ⠰ªÀ» ´Ù½Ã *
* ¼³Á¤ ÇÕ´Ï´Ù. *
* Ä«¿îÅÍ Ç¥½Ã ¹üÀ§´Â -32768 ~ 32767 ±îÁö ÀÔ´Ï´Ù. *
* *
* P3.3 = Quadrature Z Input (Clear) *
* P3.4 = Quadrature A Input *
* P3.5 = Quadrature B Input *
* TIMER1 : Mode 1 *
* *
* <<< State Diagram >>> *
* *
* /--S0---\ /--S1---\ *
* | A = 0 | ---(+)---->| A = 1 | *
* | B = 0 |<---(-)---- | B = 0 | *
* \-------/ \-------/ *
* /|\ | /|\ | *
* | | | | + : Ä«¿îÆ® °ª Áõ°¡ *
* (+)(-) (-)(+) *
* | | | | - : Ä«¿îÆ® °ª °¨¼Ò *
* | \|/ | \|/ *
* /--S3---\ /--S2---\ *
* | A = 0 | ---(-)---->| A = 1 | *
* | B = 1 |<---(+)---- | B = 1 | *
* \-------/ \-------/ *
* *
* + : Ä«¿îÆ® °ª Áõ°¡ *
* *
* <<< Linear/Rotary Encoder Pattern >>> *
* *
* 0011223344556677889999887766554433222233445566778899 *
* +---+ +---+ +---+ +---+ +---+ +---+ +--- *
* A | | | | | | | | | | | | | *
* --+ +---+ +---+ +---+ +---+ +---+ +---+ *
* +---+ +---+ +---+ +-------+ +---+ *
* B | | | | | | | | | | *
* ----+ +---+ +-------+ +---+ +---+ +----- *
* *
* 0011223344556677888877665544332211112233445566778899 *
* +---+ +---+ +---+ +-------+ +---+ +--- *
* A | | | | | | | | | | | *
* --+ +---+ +-------+ +---+ +---+ +---+ *
* +---+ +---+ +---+ +---+ +---+ +---+ *
* B | | | | | | | | | | | | *
* ----+ +---+ +---+ +---+ +---+ +---+ +----- *
* *
***********************************************************/
//
unsigned char t, u, v, current_state;
/////////////////////////////////////////////////////////////
#define RESOLUTION 1 // Á¤¹Ðµµ °ö »ó¼ö
/////////////////////////////////////////////////////////////
int task, desk;

_tmod = 0x10; // Timer 1 Mode 1 16 Bit Timer
_tr1 = 1; // Timer 1 µ¿ÀÛ ½ÃÀÛ 
_et1 = 1; // ŸÀÌ¸Ó ÀÎÅÍ·´Æ® °¡´É»óÅ ¼³Á¤ 
_ea = 1; // ±Û·Î¹ú ÀÎÅÍ·´Æ® °¡´É»óÅ ¼³Á¤

while(1) {

move_enable = 0;
desk = qabcounter;
move_enable = 1;

if (desk < 0) {
task = -desk * RESOLUTION;
Minus = 1; // Minus LED On
} else {
task = desk * RESOLUTION;
Minus = 0; // Minus LED Off
}

t = task % 100;
task = task /100;
v = task % 100;
task = task /100;
u = task % 100;

fnd_display(t, v, u);
}
}
/////////////////////////////////////////////////////////////
void pulse_counter() { // ÆÞ½º ¾÷/´Ù¿î Ä«¿îÅÍ 
/***********************************************************
* PULSE Counter *
* *
* ÆÞ½º Ä«¿îÅÍ´Â P3.2 ÇÉ¿¡ °ø±ÞµÇ´Â ÆÞ½ºÀÇ °³¼ö¸¦ ¼¼¾î *
* µð½ºÇÁ·¹ÀÌ ÇÕ´Ï´Ù. P3.2 ´Â INT0 ÀÔ´Ï´Ù. ÀÔ·ÂÆÞ½º°¡ *
* High ¿¡¼­ Low ·Î º¯ÇÒ ¶§ ÀÎÅÍ·´Æ®°¡ °É¸®¸ç *
* Ä«¿îÆ® ÇÕ´Ï´Ù. *
* P3.4¿¡ Ä«¿îÆ® Up/Down ¹æÇâÀ» ÁöÁ¤ÇÕ´Ï´Ù. *
* P3.5 ´Â Ä«¿îÅ͸¦ ¸®¼ÂÇÕ´Ï´Ù. *
* Ä«¿îÆ® °¡´É ¹üÀ§´Â -32768 ~ 32767 ±îÁö ÀÔ´Ï´Ù. *
* *
* P3.2 = Pulse Counter Input INT0 Pin *
* P3.4 = Pulse Counter Direction 1:Up Count 0:Down Count *
* P3.5 = Pulse Counter Clear *
* INT0 : Edge Sense Mode *
* *
* *
* 000011111111122222200011111111122222222211111111122222 *
* ----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-- *
* P3.2| | | | | | | | | | | | *
* +--+ +--+ +--+ +--+ +--+ +--+ *
* -------------------------------------+ +------ *
* P3.4 | | *
* +----------+ *
* -------------------+ +--------------------------------- *
* P3.5 | | *
* +-+ *
* *
***********************************************************/
//
unsigned char t, u, v;
int task, desk;

counter = 0;
_it0 = 1;
_ex0 = 1; // INT0 ÀÎÅÍ·´Æ® 
_ea = 1;

while(1) {

move_enable = 0;
desk = qabcounter;
move_enable = 1;

if (clear == 0) { // Pulse Counter Reset
counter = 0;
qabcounter = 0;
desk = 0;


if (desk < 0) {
task = -desk;
Minus = 1; // Minus LED On
} else {
task = desk;
Minus = 0; // Minus LED Off
}

t = task % 100;
task = task /100;
v = task % 100;
task = task /100;
u = task % 100;

fnd_display(t, v, u);
}

}
/////////////////////////////////////////////////////////////
void timer_mode() { // ŸÀ̸Ӡ
/***********************************************************
* Timer *
* *
* ŸÀ̸Ӵ Start ¹öÆ°À» ´©¸¥ ½Ã°¢ºÎÅÍ Stop ¹öÆ°À» *
* ´©¸¦ ¶§ ±îÁöÀÇ ½Ã°£À» ÃøÁ¤ÇÏ¿© Ç¥½Ã ÇÕ´Ï´Ù. *
* ÃÖ´ë ÃøÁ¤ ½Ã°£Àº 99 ºÐ 99 ÃÊÀ̸ç 1/100 ÃÊ ´ÜÀ§ÀÇ *
* ½Ã°£ Ç¥½Ã°¡ µË´Ï´Ù. 1 ÃÊ ¸¶´Ù ºÎÁ® ¼Ò¸®°¡ ³³´Ï´Ù. *
* Timer0 ¸¦ ¿ÀÅä ¸®·Îµå ¸ðµå(Mode 2)·Î ¼³Á¤ÇÏ°í *
* 250uS ¸¶´Ù ŸÀÌ¸Ó ÀÎÅÍ·´Æ®°¡ °É¸®µµ·Ï ÇÕ´Ï´Ù. *
* 40 °³ÀÇ ÀÎÅÍ·´Æ®°¡ °É¸®¸é 1/100 ÃÊ(Cent)°¡ µË´Ï´Ù. *
* (250uS x 40 = 10mS) 100 °³ÀÇ Cent ´Â 1 ÃÊ (Second) °¡ *
* µË´Ï´Ù. 60 ÃÊ´Â 1 ºÐ (Minute)ÀÌ µË´Ï´Ù. *
* *
* *
* P3.4 = Start *
* P3.5 = Stop *
* TIMER0 : Mode 2 *
* *
* *
* Start -----+ +---------------------------------- *
* P3.4 | | *
* +-----+ *
* Stop ----------------------------------+ +---- *
* P3.5 | | *
* +------+ *
* *
* | | *
* |<-- ½Ã°£ ÃøÁ¤ ±¸°£ -->| *
* | | *
* *
***********************************************************/
//
unsigned char second;
unsigned char minute;

iclock = 0x00;
cent = 0x00;
second = 0x00; // 00 ÃÊ·Î Ãʱ⠼³Á¤ 
minute = 0x00; // 00 ºÐÀ¸·Î Ãʱ⠼³Á¤
_tmod |= 0x02;
_th0 = 0x06; // 250 uSec
_tr0 = 1; // Timer 0 µ¿ÀÛ½ÃÀÛ 
_et0 = 1; // ŸÀÌ¸Ó ÀÎÅÍ·´Æ® °¡´É»óÅ ¼³Á¤ 
_ea = 1; // ±Û·Î¹ú ÀÎÅÍ·´Æ® °¡´É»óÅ ¼³Á¤

timer_run = 0;
fnd_display(0,0,0);
while(1) {
if (Timer_start == 0) {
timer_run = 1;
cent = 00;
second = 00; // 00 ÃÊ·Î Ãʱ⠼³Á¤ 
minute = 00; // 00 ºÐÀ¸·Î Ãʱ⠼³Á¤
}
if (Timer_stop == 0) {
timer_run = 0;
Buzer = 1; // Buzer OFF
}
if (timer_run) {
if (cent > 99) {
cent = 0;
second++;
}
if (second > 59) {
second = 0;
minute++;
}
if (minute > 59) {
minute = 0;
}
fnd_display(cent, second, minute) ;
if ((cent > 1) && (cent < 10)) { 
Buzer = 0; // Buzer ON
} else {
Buzer = 1; // Buzer OFF
}

}
}
/////////////////////////////////////////////////////////////
void clock_mode() { // µðÁöÅÐ ÀüÀڽðè 
/***********************************************************
* CLOCK *
* *
* ÃÊ ´ÜÀ§·Î µ¿ÀÛÇÏ´Â 12 ½Ã°£Á¦ Ç¥½Ã ÀüÀÚ ½Ã°èÀÔ´Ï´Ù. *
* ¾Ë¶÷ ±â´ÉÀÌ Áö¿øµË´Ï´Ù. *
* ¾Ë¶÷À» ¼³Á¤ÇÏ¸é ¼³Á¤ÇÑ ½Ã°¢ 1 ºÐ µ¿¾È¸¸ ºÎÁ® ¼Ò¸®°¡ *
* ³³´Ï´Ù. *
* *
* Timer0 ¸¦ ¿ÀÅä ¸®·Îµå ¸ðµå(Mode 2)·Î ¼³Á¤ÇÏ°í 250uS ¸¶´Ù*
* ŸÀÌ¸Ó ÀÎÅÍ·´Æ®°¡ °É¸®µµ·Ï ÇÕ´Ï´Ù. 40 °³ÀÇ ÀÎÅÍ·´Æ®°¡ *
* °É¸®¸é 1/100 ÃÊ(Cent)°¡ µË´Ï´Ù. (250uS x 40 = 10mS) *
* 100 °³ÀÇ Cent ´Â 1 ÃÊ (Second) °¡ µË´Ï´Ù. 60 ÃÊ´Â *
* 1 ºÐ (Minute)À̵˴ϴÙ. 60 ºÐÀº 1½Ã°£(Hour) ÀÌ µË´Ï´Ù. *
* *
* P3.2 = ALARM ¼³Á¤ LED GREEN *
* P3.3 = ÀúÀå LED YELLOW *
* P3.4 = ½Ã(Hour) ¼³Á¤ LED RED *
* P3.5 = ºÐ(ºÐ) ¼³Á¤ LED RED *
* TIMER0 = Mode 2 *
* *
* <<< ½Ã°£ ¼³Á¤ >>> *
* Hour ¹öÆ°: ½Ã¸¦ Á¶Á¤ÇÒ ¶§ ´©¸¨´Ï´Ù. *
* Min ¹öÆ°: ºÐÀ» Á¶Á¤ÇÒ ¶§ ´©¸¨´Ï´Ù. *
* *
* <<< ¾Ë¶÷½Ã°¢ ¼³Á¤ >>> *
* ALARM ¹öÆ°À» ´©¸¨´Ï´Ù. *
* Hour ¹öÆ°°ú Min ¹öÆ°À» »ç¿ëÇÏ¿© ¾Ë¶÷ ½Ã°¢À» ¼³Á¤ÇÕ´Ï´Ù. *
* Save ¹öÆ°À» ´­·¯ ALARM ½Ã°¢À» ÀúÀå ÇÕ´Ï´Ù. *
* ALARM ÀÌ ¼³Á¤µÇ¸é P3.3 ÀÌ LOW °¡ µÇ¾î ALARM Ç¥½Ã *
* LED °¡ ON µË´Ï´Ù. *
* ALARM ½Ã°¢¿¡ ºÎÁ®°¡ ¿ï¸®Áö ¾Ê°Ô ÇÏ·Á¸é ALARM ¹öÆ°À» *
* ´­·¯ ÀúÀåÇÏÁö ¾Ê°í ALARM ¼³Á¤ ¸ðµå¸¦ ºüÁ® ³ª°©´Ï´Ù. *
* *
***********************************************************/
//
unsigned char second;
unsigned char minute;
unsigned char hour;
unsigned char alarm_minute;
unsigned char alarm_hour;

alarm_hour = 12;
alarm_minute = 0;
hour = 12; // 12 ½Ã·Î Ãʱ⠼³Á¤ 
minute = 0; // 00 ºÐÀ¸·Î Ãʱ⠼³Á¤
second = 0; // 00 ÃÊ·Î Ãʱ⠼³Á¤ 
cent = 0;

_tmod = 0x02; // Auto Reload Mode
_th0 = 0x06; // 250 uSec ÀÎÅÍ·´Æ® ÁÖ±â 
_tr0 = 1; // Timer 0 µ¿ÀÛ½ÃÀÛ 
_et0 = 1; // ŸÀÌ¸Ó ÀÎÅÍ·´Æ® °¡´É»óÅ ¼³Á¤ 
_ea = 1; // ±Û·Î¹ú ÀÎÅÍ·´Æ® °¡´É»óÅ ¼³Á¤

while(1) {
////////////////////////////////////////////////////////////
if (cent > 99) {
cent = 0;
second++;
}
if (second > 59) {
second = 0;
minute++;
}
if (minute > 59) {
minute = 0;
hour++;
}
if (hour > 12) {
hour = 1;
}
fnd_display(second, minute, hour); // ½Ã, ºÐ, Ãʸ¦ Ç¥½Ã 
////////////////////////////////////////////////////////////
if ((Set_save == 0) && (alarm_hour == hour) && (alarm_minute == minute)) {
Buzer = 0; // ¾Ë¶÷ ºÎÁ® À½ 
} else { // 1 ºÐ µ¿¾È¸¸ ºÎÁ® µ¿ÀÛ
Buzer = 1;
}
////////////////////////////////////////////////////////////
if (Set_hour == 0) { // ½Ã ´ÜÀ§ Á¶Á¤
hour = hour + 1;
delay();
}
if (Set_minute == 0) { // ºÐ ´ÜÀ§ Á¶Á¤ 
minute++;
second = 0;
cent = 0;
delay();
}
////////////////////////////////////////////////////////////
if (Set_alarm == 0) {
Set_save = 1; // ALARM LED Off
while(1) {
fnd_display(0, alarm_minute, alarm_hour);
delay(); 
if (Set_hour == 0) { 
alarm_hour++;
if (alarm_hour > 12) {
alarm_hour = 1;

delay();
}
if (Set_minute == 0) { 
alarm_minute++;
if (alarm_minute > 59) {
alarm_minute = 0;
}
delay();
}
if (Set_save == 0) {
Set_save = 0; // ALARM LED On
break;
}
if (Set_alarm == 0) { // ALARM Off
delay();
break;
}
}
}
////////////////////////////////////////////////////////////

}
/////////////////////////////////////////////////////////////
main() {
/***********************************************************
* SE-CLOCK-UNI *
* *
* SE-CLOCK-UNI Á¶¸³ KIT Àº µ¿ÀÏÇÑ È¸·Î·Î 4 °¡ÁöÀÇ ´Ù¸¥ *
* ½Ã½ºÅÛÀ» ¸¸µå´Â ¿¹¸¦ º¸ÀÎ °ÍÀÔ´Ï´Ù. Á¶¸³ ¿Ï¼ºÈÄ ÆÄ¿ö¸¦ *
* ¿¬°áÇϸé P3.0, P3.1 À» È®ÀÎÇÏ¿© 4 °¡Áö Áß 1 °¡Áö ¸ðµå·Î * *
* µ¿ÀÛÇÕ´Ï´Ù. *
* *
* P3.1 P3.0 *
* Open Open ---> CLOCK *
* Open Short ---> TIMER *
* Short Open ---> PULSE COUNTER *
* Short Short ---> QUADRATURE COUNTER *
* *
* CLOCK : ÃÊ´ÜÀ§ Ç¥½ÃÀÇ ÀüÀÚ ½Ã°è *
* TIMER : 1/100 ÃÊ´ÜÀ§·Î 99ºÐ±îÁö ÃøÁ¤µÇ´Â ŸÀÌ¸Ó *
* PULSE COUNTER : ÆÞ½º ¾÷/´Ù¿î °è¼ö±â *
* QUADRATURE COUNTER : ·ÎÅ͸®/¸®´Ï¾î ¿£ÄÚ´õ A/B »ó Ä«¿îÅÍ *
* *
* *
* Crossware 8051 ANSI C µ¥¸ð¹öÁ¯ ÄÄÆÄÀÏ·¯¸¦ ÀÌ¿ëÇÏ¿© *
* HEX ÆÄÀÏ ¸¸µå´Â ¼ø¼­: *
* *
* << ù¹ø° ¹æ¹ý >> *
* Step 1: Crossware 8051 ANSI C ÄÄÆÄÀÏ·¯ ´Ù¿î·Îµå ÇÏ°í *
* PC ¿¡ ¼³Ä¡ÇÕ´Ï´Ù. *
* http://www.crossware.co.kr/setup-demo.exe *
* *
* Step 2: Crossware C ÄÄÆÄÀÏ·¯¸¦ ½ÇÇàÇÕ´Ï´Ù. *
* *
* Step 3: »õ·Î¿î ÇÁ·ÎÁ§Æ®¸¦ ¸¸µì´Ï´Ù. *
* 1. FILE ¸Þ´º¿¡¼­ New ¸¦ ¼±ÅÃÇÕ´Ï´Ù. *
* New âÀÌ ³ª¿É´Ï´Ù. Project ÅÇ¿¡¼­ Executable *
* Program À» ¼±ÅÃÇÏ°í [È®ÀÎ]À» Ŭ¸¯ÇÕ´Ï´Ù. *
* 2. Target Select âÀÌ ³ª¿À¸ç *
* Target Family: 8051 *
* Group : Show All *
* Family Member: Generic 8051 À» ¼±ÅÃÇÕ´Ï´Ù.*
* [´ÙÀ½]À» Ŭ¸¯ÇÕ´Ï´Ù. *
* 3. Project Name and Directory âÀÌ ³ª¿É´Ï´Ù. *
* Project name Ä­¿¡ ÇÁ·ÎÁ§Æ® À̸§À» *
* se-clock-uni·Î ÀÔ·ÂÇÕ´Ï´Ù. *
* Project Directory¸¦ º¯°æÇÏ·Á¸é [Browse]¹öÆ°À»*
* ÀÌ¿ëÇÏ¿© »õ·Î¿î µð·ºÅ丮¸¦ ¼±ÅÃÇÕ´Ï´Ù. *
* [´ÙÀ½] ¹öÆ°À» Ŭ¸¯ÇÕ´Ï´Ù. *
* 4. Target Memory Configuration âÀÌ ³ª¿É´Ï´Ù. *
* Memory Model À» Small ·Î ¼±Åà ÇÕ´Ï´Ù. *
* [´ÙÀ½]À» Ŭ¸¯ÇÕ´Ï´Ù. *
* 5. Program File Format âÀÌ ³ª¿À¸ç ¿©±â¼­ *
* INTEL HEX ¸¦ ¼±ÅÃÇÕ´Ï´Ù. *
* [´ÙÀ½]À» Ŭ¸¯ÇÕ´Ï´Ù. *
* 6. Start up File âÀÌ ³ª¿É´Ï´Ù. *
* [¸¶Ä§]À» Ŭ¸¯Çϸé Project ÃʱâÈ­°¡ ¿Ï·áµÇ¸ç *
* main.c ±âº» ÇÁ·Î±×·¥ÀÌ ¸¸µé¾î Áý´Ï´Ù. *
* ÀüºÎ Áö¿ì°í SE-CLOCK-UNI ÇÁ·Î±×·¥À» º¹»çÇÏ¿© *
* ³Ö½À´Ï´Ù. *
* Step 4: Build ¸Þ´º¿¡¼­ Rebuild All À» Ŭ¸¯Çϸé *
* se-clock-uni.HEX ÆÄÀÏÀÌ ¸¸µé¾îÁý´Ï´Ù. *
* *
* *
* << µÎ¹ø° ¹æ¹ý >> *
* Step 1: Crossware 8051 ANSI C ÄÄÆÄÀÏ·¯ ´Ù¿î·Îµå ÇÏ°í *
* PC ¿¡ ¼³Ä¡ÇÕ´Ï´Ù. *
* http://www.crossware.co.kr/setup-demo.exe *
* Step 2: c:\estudio_demo\projects Æú´õ¿¡¼­ »õ Æú´õ *
* ¸¸µé±â¸¦ ÇÏ°í Æú´õ À̸§À» se-clock-uni ·Î *
* ÀÔ·ÂÇÕ´Ï´Ù. *
* se-clock-uni.zip ¸¦ ¾ÐÃàÀ» Ç®¾î *
* c:\estudio_demo\projects\se-clock-uni Æú´õ¿¡ *
* º¹»çÇÏ¿© ³Ö½À´Ï´Ù. *
* Step 3: 1. Crossware ¸¦ ½ÇÇàÇÕ´Ï´Ù. *
* 2. FILE ¸Þ´º¿¡¼­ Open Project¸¦ Ŭ¸¯ÇÕ´Ï´Ù. *
* 3. se-clock-uniÆú´õ¿¡¼­ se-clock-uni.XMK¸¦ *
* ¼±ÅÃÇÕ´Ï´Ù. *
* Step 4: Build ¸Þ´º¿¡¼­ Rebuild All À» Ŭ¸¯Çϸé *
* se-clock-uni.HEX ÆÄÀÏÀÌ ¸¸µé¾îÁý´Ï´Ù. *
* *
* *
* os.h ¿Í sfr.h Çì´õ ÆÄÀÏÀº Crossware 8051 C ÄÄÆÄÀÏ·¯°¡ *
* ¼³Ä¡µÇ¸é include Æú´õ¾È¿¡ µé¾î ÀÖ½À´Ï´Ù. *
* *
* (c)SAMPLE Electronics co. HTTP://WWW.SAMPLE.CO.KR *
* *
***********************************************************/
//
unsigned char c;

Minus = 0; // FND1ÀÇ Minus ºÎÈ£¸¦ OFF 

c = _p3 & 0x03; // P3.0°ú P3.1 À» ÀÐ¾î µ¿ÀÛ ¸ðµå °áÁ¤ 

if (c == 3) { // P3.1 = 1 P3.0 = 1
clock_mode(); // ½Ã°è ¸ðµå
}

if (c == 2) { // P3.1 = 1 P3.0 = 0
timer_mode(); // ŸÀÌ¸Ó ¸ðµå 
}

if (c == 1) { // P3.1 = 0 P3.0 = 1
pulse_counter(); // ÆÞ½º ¾÷/´Ù¿î Ä«¿îÅÍ ¸ðµå 
}

if (c == 0) { // P3.1 = 0 P3.0 = 0
quadrature_counter(); // AB »ó Ä«¿îÅÍ ¸ðµå 
}
}
/////////////////////////////////////////////////////////////
/******************** End of FILE ************************/

¡¡

¡¡

»ùÇÃÀüÀÚ ½Ã°è Á¶¸³ KIT ºñ±³Ç¥
(±×¸²À» Ŭ¸¯ÇÏ½Ã¸é °ü·Ã ÆäÀÌÁö·Î À̵¿ÇÕ´Ï´Ù.)

SE-CLOCK-UNI


Lan: C ¾ð¾î
CPU: AT89C51
±âÆÇ: ¸¸´É±âÆÇ

SE-CLOCK-FND


Lan: BASIC
CPU: AT89C51
±âÆÇ: ¾ç¸é PCB

SE-CLOCK-LED


Lan: C, BASIC
CPU: AT89C2051
±âÆÇ: ´Ü¸é PCB

SE-CLOCK-LED-U


Lang: C, BASIC
CPU: AT89C2051
±âÆÇ: ¸¸´É±âÆÇ

SE-CLOCK-DM


Lan: C, BASIC
CPU: AT89C2051
±âÆÇ: ¾ç¸é PCB

SE-CLOCK-DM-U


Lan: C, BASIC
CPU: AT89C2051
±âÆÇ: ¸¸´É±âÆÇ

SE-CLOCK-ES


Lan: C, BASIC
CPU: AT89C51
±âÆÇ: ´Ü¸é PCB

SE-CLOCK-MINI


Lan: BASIC
CPU: AT89C2051
±âÆÇ: ¾ç¸é PCB

¡¡

°¡ °Ý Á¤ º¸

*** CPU ¿¡ HEX ÆÄÀÏÀÌ ¶óÀÌÆõǾî ÀÖ½À´Ï´Ù. ***
*** KIT ¿¡ ¾Æ´äÅÍ, °ÇÀüÁö, ¿£ÄÚ´õ´Â Æ÷ÇÔµÇÁö ¾Ê½À´Ï´Ù. ***

os.h ¿Í sfr.h ´Â Crossware 8051 C ÄÄÆÄÀÏ·¯¸¦ PC ¿¡ ¼³Ä¡ÇϽøé
C:\embedded_demo\8051\include Æú´õ ¾È¿¡ µé¾îÀÖ½À´Ï´Ù.
Åùè·Î ÁÖ¹®ÇϽ÷Á¸é Åùè·á¸¦ Æ÷ÇÔÇÑ 24,500¿ø(22,000 + 2,500)À»
±¹¹ÎÀºÇà °èÁ·Π¼Û±ÝÇØ Áֽðí ÀüÈ­/¸ÞÀÏ·Î ¹Þ´Â
ÁÖ¼ÒÁö¿Í ÀüÈ­¹øÈ£¸¦ ¾Ë·Á ÁÖ½Ã¸é µË´Ï´Ù. ¸ÞÀÏÀ»
º¸³»Áֽøé ÅÃ¹è ¿î¼ÛÀå ¹øÈ£¸¦ ¸ÞÀÏ·Î ¾Ë·Á µå¸³´Ï´Ù.

¡¡