100 likes | 309 Views
#include <io51.h> unsigned char Triger = 0; void inter_init (void) { TMOD = 0x12; /* 타이머 1 모드 1 , 타이머 0 모드 2 */ TR0 = 1; ET0 = 1; /* Xtal 이 20M 일때 20M / 12 분주 = 0.6usec */ /* 0x100 - 22 = 0xEA , 22 * 0.6usec = 13.2usec 인터럽트 설정 */ TH0 = 0xEA; TL0 = 0xEA; TR1 = 1;
E N D
#include <io51.h> • unsigned char Triger = 0; • void inter_init(void) • { • TMOD = 0x12; /* 타이머1모드1 , 타이머0모드2 */ TR0 = 1; • ET0 = 1; /* Xtal이 20M 일때 20M / 12분주 = 0.6usec */ /* 0x100 - 22 = 0xEA , 22 * 0.6usec = 13.2usec 인터럽트 설정 */ • TH0 = 0xEA; • TL0 = 0xEA; • TR1 = 1; • ET1 = 1; • /* Xtal이 20M 일때 20M / 12분주 = 0.6usec */ • /* 0x10000 - 41666 = 0x5d3e , 41666 * 0.6usec = 25musec 인터럽트 설정 */ • TH1 = 0x5d; • TL1 = 0x3e; • EA = 1; • } • /*13.2uSec interrupt rut*/ • interrupt [0x0B] void T0_int(void) • { • P3 ^= 0x02; //적외선 On, Off • } • /*25mSec interrupt rut*/ • interrupt [0x1B] void T1_int(void) • { • switch (Triger) • { • case 0: Triger = 1;//적외선 Off
ET0 = 0; P3 |= 0x02; • break; • case 1: Triger = 0;//적외선 On • ET0 = 1; P3 &= ~0x02; • break; • } • TH1 = 0x5d; • TL1 = 0x3e; • } • void main(void) • { • unsigned int k; • inter_init(); • while(1) • { • for (k = 0 ; k <= 60000 ; k ++); • P3 ^= 0x01; • } • } • 수신부 소스
#include <io51.h> • /* Port 3 */ • #define RS 0x01 • #define EN 0x02 • #define LCD_RS_0 P3 &= ~RS • #define LCD_RS_1 P3 |= RS • #define LCD_EN_0 P3 &= ~EN • #define LCD_EN_1 P3 |= EN • /* Port 2 */ • #define BUZ 0x01 • #define CLEAR 0x02 • #define LED 0x04 • #define BUZ_ON P2 &= ~BUZ; • #define BUZ_OFF P2 |= BUZ; • #define LED_ON P2 &= ~LED; • #define LED_OFF P2 |= LED; • #define CLEAR_read P2 & CLEAR • #include "lcd16x2.h" • unsigned long MAN_FLAG = 0; • unsigned char MAN_ONE_FLAG = 0; • unsigned char BUZER_FLAG = 0; • unsigned long buz_cnt = 0; • unsigned long led_cnt = 0; • unsigned long visitor_number = 0;
void disp_vis (unsigned long number) • { • unsigned char data_1, data_2, data_3, data_4, data_5; • data_1 = number / 10000; • number = number - (10000 * data_1); • data_2 = number / 1000; • number = number - (1000 * data_2); • data_3 = number / 100; • number = number - (100 * data_3); • data_4 = number / 10; • number = number - (10 * data_4); • data_5 = number; • lcd_1char (9,1,'0'+data_1); • lcd_1char (10,1,'0'+data_2); • lcd_1char (11,1,'0'+data_3); • lcd_1char (12,1,'0'+data_4); • lcd_1char (13,1,'0'+data_5); • } • void init_port() • { • P2 |= CLEAR; //클리어버턴 입력 • LED_OFF; • BUZ_OFF; • } • void init_interrupt() • {
TMOD = 0x10; //타이머1 모드1 설정(16비트) • TR1 = 1; • EA = 1; • ET1 = 1; • TH1 = 0xFD; • TL1 = 0x65; • IT0 = 1; • EX0 = 1; • } • interrupt [0x03] void EX0_int (void) • { • MAN_FLAG = 0; • MAN_ONE_FLAG = 1; • LED_ON; • led_cnt = 0; • } • /*1m Sec interrupt rut*/ • interrupt [0x1B] void T1_int(void) • { • TH1 = 0xFD; • TL1 = 0x65; • P1 ^= 0x01; • MAN_FLAG ++; • if (MAN_ONE_FLAG == 1) • { • if (MAN_FLAG >= 100)
{ • BUZER_FLAG = 1; • MAN_FLAG = 0; • visitor_number ++; // 방문객 숫자 +1 한다. • } • } • if (BUZER_FLAG == 1) • { • BUZ_ON; • buz_cnt ++; • if (buz_cnt >= 100) {BUZ_OFF; buz_cnt = 0; BUZER_FLAG = 0; MAN_ONE_FLAG = 0;} • } • led_cnt ++; • if (led_cnt >= 100) {LED_OFF; led_cnt = 100;} • } • void main() • { • unsigned char lcd_0[16] = {'V','i','s','i','t','o','r',' ',' ',' ',' ',' ',' ',' ',' ',' '}; • unsigned char lcd_1[16] = {'N','u','m','b','e','r',' ','=','0','0','0','0','0',' ',' ',' '}; • unsigned long k; • init_port(); • BUZ_OFF; • LED_OFF; • for (k = 0 ; k <= 1000 ; k ++); • visitor_number = 0; • init_lcd();
init_interrupt(); • for (k = 0 ; k <= 15 ; k ++) • { • lcd_1char (k,0,lcd_0[k]); • lcd_1char (k,1,lcd_1[k]); • } • while(1) • { • if (!(CLEAR_read)) • { • visitor_number = 0;disp_vis(visitor_number); • } • disp_vis(visitor_number); • for (k = 0 ; k <= 100 ; k ++); • } • }