外部震荡源中断的计时实验

来源:本站
导读:目前正在解读《外部震荡源中断的计时实验》的相关信息,《外部震荡源中断的计时实验》是由用户自行发布的知识型内容!下面请观看由(电工技术网 - www.9ddd.net)用户发布《外部震荡源中断的计时实验》的详细说明。
简介:cd4060和2.048M晶体构成的方波震荡源用500Hz的输出连到ATmega16的PD3 ,INT1中断500次是1秒构成计时基准。

PA0-PA7 连到八段数码管的a-p ,PC0-PC5 分别连六个数码管的共阴极

c程序:

/*****************************************************

This program was produced by the

CodeWizardAVR V2.05.5a Evaluation

Date : 2011/12/14

Author : Freeware, for evaluation and

non-commercial use only

Chip type : ATmega16

Program type : Application

AVR Core Clock frequency: 4.000000 MHz

Memory model : Small

External RAM size : 0

Data Stack size : 256

*****************************************************/

#include <mega16.h>

#include <delay.h>

flash unsigned char led_7[10] = {0x3F,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};

flash unsigned char position[6]= {0xfe,0xfd,0xfb,0xf7,0xef,0xdf};

unsigned char time[3];

unsigned char dis_buff[6];

int time_counter;

unsigned char posit;

bit point_on,time_1s_ok;

void display(void)

{

unsigned char i;

for(i=0 ;i<=5; i++)

{

PORTC = 0xff; //防止在PORTC在上个循环选定的位置的数码管输出,造成一个数码管输出两个不同的数,从而在视觉上产生错误的图像

PORTA = led_7[dis_buff[i]];

if (point_on && (i==2 || i==4 )) PORTA |= 0x80;

PORTC = position[i];

}

PORTC = 0xff; //使最后一个数码管显示的时间 和前5个基本一样 这样亮度才能均匀

}

interrupt [EXT_INT1] void ext_int1_isr(void)

{

if ( ++time_counter >= 500)

{

time_counter = 0;

time_1s_ok = 1;

}

}

void time_to_disbuffer(void)

{

unsigned char i,j = 0;

for(i=0 ; i <=2; i++)

{

dis_buff[j++] = time[i] %10;

dis_buff[j++] = time[i] /10;

}

}

void main(void)

{

PORTA = 0x00;

DDRA = 0xFF;

PORTC = 0x3f;

DDRC = 0x3f;

time[2] = 23; time[1] = 58 ; time[0]=55 ;

posit = 0;

time_to_disbuffer();

GICR |= 0x80;

MCUCR = 0x08;

GIFR = 0x80;

#asm("sei")

while(1)

{

display();

if(time_1s_ok)

{

time_1s_ok = 0;

point_on = ~point_on;

if( ++time[0] >= 60)

{

time[0] = 0;

if(++time[1] >=60)

{

time[1] = 0;

if(++time[2] >=24 ) time[2] = 0;

}

}

time_to_disbuffer();

}

} ;

}

提醒:《外部震荡源中断的计时实验》最后刷新时间 2024-03-14 01:08:30,本站为公益型个人网站,仅供个人学习和记录信息,不进行任何商业性质的盈利。如果内容、图片资源失效或内容涉及侵权,请反馈至,我们会及时处理。本站只保证内容的可读性,无法保证真实性,《外部震荡源中断的计时实验》该内容的真实性请自行鉴别。