马老师6--4课后问题答案
/*********************************************File name : demo_6_4.c
Chip type : ATmega16
Program type : Application
Clock frequency : 4.000000 MHz
Memory model : Small
External SRAM size: 0
Data Stack size : 256
*********************************************/
#include <mega16.h>
#include <delay.h>
flash unsigned char led_7={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,
0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71};
bit point_on = 1;
void main(void)
{
unsigned char i ;
PORTA=0xFF;
DDRA=0xFF;
while (1)
{
for (i=0;i<=15;i++)
{
PORTA = led_7;
if (point_on) PORTA |= 0x80;
delay_ms(500);
if (point_on) PORTA &= 0x7F;
delay_ms(500);
}
// point_on = ~point_on;
}
}
在位上定义的不是太好,有更好方法应该,大家给点意见 这个程序只是个非常简单的示例,里面的point_on是的标志信号量,其作用当你学到后面,如11.4就会有更深的体会.
如果仅仅是这个简单例子的思考和实现,当然不需要这样麻烦:
for (i=0;i<=15;i++)
{
PORTA = led_7;
delay_ms(500);
PORTA.7 = 1;
delay_ms(500);
} 呵呵太忙了,自己发的帖子都好久没来看了,以上问题现在已经不是问题了,谢谢马老师.
页:
[1]