20121204 作業1 20121204 作業1

 //----------------------------------------------------------------

//
// Project : station_1_02
// File mane : station_1_02.c
// Hex file: station_1_02.hex
// Note :The second C program of station 1
// Compiler : Keil C
// Version : ver4(04/12/2012)
// Revision : 1. to modify the connection of buzzer(P3.0 -> P3.5)
// 2. to modify the frequency of buzzer
// 資訊工程 9879005 黃階輝 日期2012-12-4 作業微處理機應用實務
//----------------------------------------------------------------
#include <reg51.h>
sbit P1_4 = P1^4; // INPUT
sbit P3_5 = P3^5; // BUZZER
sbit P3_3 = P3^3; // PB_SW
int t = 64820; // So=784Hz, 65536-716=64820
void delay(int);
main()
{
unsigned char i;
int j;
IE = 0x84;
TMOD = 0x01;
TCON = 0x00;
P2 = 0xff;
while(1)
{
i = 0x00;
if(P1_4 == 0)
{
for (j = 1; j <= 6; j++)
{
P2 = ~i;
delay(30); // 20ms *40 = 800ms = 0.8s
i = ~i;
}
P2 = 0xff;
}
}
}
void delay(int count) // delay 20ms
{
int m, n;
for(m = 1; m <= count; m++)
{
for(n = 1; n <= 2000; n++)
{
;
}
}
 
}
void EX1_int(void) interrupt 2
{
int j;
for(j = 1; j <= 250; j++)
{
P3_5 = 1;
TH0 = t /256;
TL0 = t % 256;
TR0 = 1;
while(TF0 == 0)
{
;
}
TF0 = 0;
P3_5 = 0;
TH0 = t /256;
TL0 = t % 256;
TR0 = 1;
while(TF0 == 0)
{
;
}
TF0 = 0;
}
}