#include<math.h>
#include<dos.h>
#include<graphics.h>
#define CENTERX 320 /*表盘中心位置*/
#define CENTERY 175
#define CLICK 100 /*喀嗒声频率*/
#define CLICKDELAY 30 /*喀嗒声延时*/
#define HEBEEP 10000 /*高声频率*/
#define LOWBEEP 500 /*低声频率*/
#define BEEPDELAY 200 /*报时声延时*/
/*表盘刻度形状*/
int Mrk_1[8]={-5,-160,5,-160,5,-130,-5,-130, }
int Mrk_2[8]={-5,-160,5,-160,2,-130,-2-130, }
/*时针形状*/
int HourHand[8]={-3,-100,3,-120,4, 10,-4,10}
/*分针形状*/
int MiHand[8]={-3,-120,3,-120,4, 10,-4,10}
/*秒针形状*/
int SecHand[8]={-2,-150,2,-150,3, 10,-3,10}
/*发出喀嗒声*/
void Click()
{
sound(CLICK)
delay(CLICKDELAY)
nosound()
}
/*高声报时*/
void HighBeep()
{
sound(HEBEEP)
delay(BEEPDELAY)
nosound
}
/*低声报时*/
void LowBeep()
{
sound(LOWBEEP)
}
/*按任意角度画多边形*/
void DrawPoly(int *data,int angle,int color)
{
int usedata[8]
float sinang,cosang
int i
sinang=sin((float)angle/180*3.14)
cosang=cos((float)angle/180*3.14)
for(i=0i<8i+=2)
{
usedata[i] =CENTERX+ cosang*data[i]-sinang*data[i+1]+.5
usedata[i+1]=CENTERY+sinang*data[i]+cosang*data[i+1]+.5
}
setfillstyle(SOLID_FILL,color)
fillpoly(4,usedata)
}
/*画表盘*/
void DrawClock(struct time *cutime)
{
int ang
float hourrate,minrate,secrate
setbkcolor(BLACK)
cleardevice()
setcolor(WHITE)
/* 画刻度*/
for(ang=0ang<360ang+=90)
{
DrawPoly(Mrk_1,ang,WHITE)
DrawPoly(Mrk_2,ang+30,WHITE)
DrawPoly(Mrk_2,ang+60,WHITE)
}
secrate=(float)cutime->ti_sec/60
minrate=((float)cutime->ti_min+secrate)/60
hourrate=(((float)cutime->ti_hour/12)+minrate)/12
ang=hourrate*360
DrawPoly(HourHand,ang,YELLOW)/*画时针*/
ang=minrate*360
DrawPoly(MiHand,ang, GREEN)/*画分针*/
ang=secrate*360
DrawPoly(SecHand,ang, RED)/*画秒针*/
}
main()
{
int gdriver=EGA,
gmode=EGAHI
int curpage
struct time curtime ,newtime
initgraph(&gdriver,&gmode,"c:\\tc")
setbkcolor(BLUE)
cleardevice()
gettime(&curtime)
curpage=0
DrawClock(&curtime)
while(1)
{
if(kbhit())
break/*按任意键退出*/
gettime(&newtime)/*检测系统时间*/
if(newtime.ti_sec!=curtime.ti_sec)/*每1秒更新一次时间*/
{
if(curpage==0)
curpage=1
else
curpage=0
curtime=newtime
/*设置绘图页*/
setactivepage(curpage)
/*在图页上画表盘*/
DrawClock(&curtime)
/*设置绘图页为当前可见页*/
setvisualpage(curpage)
/*0分0秒高声报时*/
if(newtime.ti_min==0&&newtime.ti_sec==0)
HighBeep()
/* 59分55至秒时低声报时*/
else if(newtime.ti_min==59&&
newtime.ti_sec<=59)
LowBeep()/*其他时间只发出喀嗒声*/
else
Click()
}
}
closegraph()
} 赞同0| 评论
参考以下方法。打开需要录制的视频,点击“屏幕录制”,点击“结束”,可以结束录制。
Mouser Electronics可供应PIC16F887-I/P 8位微控制器 -MCU。
给你一个PIC写的接收红外遥控器的程序。//******************************************************
//mcu: PIC16F883
//author:
//data:
//ver: 1.0
//********************************************************
#include <pic.h>
#include <pic16f887.h>
#include "main.h"
// 函数声明部份
void interrupt IRQ_TEST(void)
void fun_intset(void)
void set_port(void)
void fun_timerset(void)
void delay_10us(void)
void delay_130us(void)
void test_remote(void)
// 主函数
void main()
{
set_port()
fun_timerset()
fun_intset()
delay_10ms()
ram_ini()
GIE=1
while(1)
{
asm("clrwd")
test_remote()
}
}
//端口I/O定义子程序
void set_port()
{
ANSEL =0X00//porta io port
ANSELH=0X00 //portb io port
//TRISX BIT=1, PORTX AS INPUT
TRISA = 0x0F//RA0-RA3 INPUT ,RA4-RA5 OUTPUT
TRISB = 0x07//RB0 PASS0, RB1-RB2 INPUT ,RB3-RB6 OUTPUT
TRISC = 0x0F
// TRISC = 0x03//RC0-RC1 INPUT,RC5-RC6 OUTPUT , RC3 RC4 EEPROM SCL SDA
PORTC=0
PORTA=0XFF
// WPUB=0XFF
PORTB=0X07
}
//中断子程序
void interrupt IRQ_TEST(void)
{
if(T0IF) //Timer0中断服务子程序
{
TMR0=0xce
T0IF=0
timer_100us++ //100us
}
if(INTF==1)
{
INTF=0
timer_rec=timer_100us
timer_100us=0
flag_rec_remote=1
}
}
//定时器0初始化设置子程序
void fun_timerset()
{
//Timer0初始化设置
PSA=0//Timer0 使用预分频器
//Timer0选择分频率为1:2
PS0=0PS1=0PS2=0
//内部时钟定时方式,定时时间:200uS,误差:0uS
T0CS=0
// TMR0=0x9b
TMR0=0xce//100us
}
/*
//定时器2初始化设置子程序
void fun_timer2set()
{
//Timer2初始化设置
//timer2使用预分频率1:1
T2CKPS0=0T2CKPS1=0
//timer2使用后分频率1:1
TOUTPS0=0
TOUTPS1=0
TOUTPS2=0
TOUTPS3=0
//定时器2定时时间为:200uS,误差:0uS
TMR2=0x38
TMR2ON=1
}
*/
//中断允许设置子程序
void fun_intset()
{
T0IE=1//Tiemr0中断允许
INTEDG=0//RB0 FALLAGE INTERRUPT
INTE=1
INTF=0
}
void ram_ini(void)
{
}
//------------------------------------------------------------
//*****************************************************************************
void delay_10us(void)
{
NOP
NOP
NOP
NOP
NOP
NOP
}
void delay_130us(void)
{
uchar i
for(i=0i<13i++)
{
NOP
NOP
NOP
}
}
void delay_10ms(void)
{
unsigned int i
for(i=0i<1000i++)
{
NOP
NOP
NOP
NOP
NOP
}
}
void test_remote(void)
{
uchar rec_ok,i
if(flag_rec_remote==1)
{
flag_rec_remote=0
// remote_buf[rec_byte]=timer_rec //test use
// rec_byte++//test use
// return //test use
if(flag_rec_head==0)
{
if(timer_rec>=90&&timer_rec<=140) //135
{
flag_rec_head=1
rec_byte=0
rec_bit=0
rec_buf=0
return
}
}
else
{
if(timer_rec>=8&&timer_rec<=12) //11.2
{
rec_buf=(rec_buf>>1)
rec_buf=rec_buf&0x7f
}
else if(timer_rec>=18&&timer_rec<=22) //22
{
rec_buf=(rec_buf>>1)
rec_buf=rec_buf|0x80
}
else if(timer_rec>=90&&timer_rec<=140)
{
flag_rec_head=1
rec_byte=0
rec_bit=0
rec_buf=0
return
}
else
{
flag_rec_head=0
rec_byte=0
rec_bit=0
rec_buf=0
return
}
}
if(flag_rec_head==1)
{
rec_bit++
if(rec_bit==8)
{
remote_buf[rec_byte]=rec_buf
rec_byte++
rec_bit=0
if(rec_byte==4)
{
NOP
NOP
NOP
NOP
rec_byte=0
rec_bit=0
rec_buf=0
flag_rec_head=0
}
}
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)