让大家等了这么长时间,呵呵,急忙赶了一部分东西出来了,请大家看看。
第一部分 准备学习avr的工具
1、 JTAG仿真器
2、 AVR STK500/ISP下载器或者usb简易下载器
3、 学习板
在该学习板中,我们采用了usb供电,节省了电源,降低了开发成本。
4、 PC
电脑人人都有,现在我们的仿真器和stk500都是采用usb接口,所以,一般电脑都可以使用。
5、STK500的使用方法。具体参考资料。
6、jatg使用方法。具体参考资料手册。
第二部分 M16 点亮LED
1、 建立工程
2、 建立好工程以后,我们就开始选择芯片如下图所示:
选择好芯片,如图所示:
此时,我们点击OK,然后编写程序。
3、 我们的硬件LED对应的关系如下:
D1-----------------------PA6
D2-----------------------PA7
D3-----------------------PC0
D4-----------------------PC1
D5-----------------------PC6
D6-----------------------PC7
4、 我们编写如下的程序
//ICC-AVR application builder : 2008-12-17 19:24:22
// Target : M16
// Crystal: 7.3728Mhz
//南京华岳电子
http://www.njhuayue.com/
//淘宝店铺:
http://shop36473995.taobao.com/
#include
#include
//****************************************
//延时子程序
//****************************************
void DELAY()
{
unsigned char i,j,k;
for(i=0;i<250;i++)
{
for(j=0;j<250;j++)
{
for(k=0;k<10;k++)
{
;
}
}
}
}
//*****************************************
//io端口初始化子程序
//*****************************************
void port_init(void)
{
PORTA = 0xc0;
DDRA = 0xc0;
PORTB = 0x00;
DDRB = 0x00;
PORTC = 0xC3; //m103 output only
DDRC = 0xC3;
PORTD = 0x00;
DDRD = 0x00;
}
//*****************************************
//程序初始化
//*****************************************
//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x00; //timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
//*****************************************
//主程序
//*****************************************
void main(void)
{
init_devices(); //初始化芯片
//insert your functional code here...
//io循环程序
while(1)
{
PORTA|=0B11000000;
PORTC|=0B11000011;
DELAY();
PORTA&=0B00111111;
PORTC&=0B00111100;
DELAY();
}
}
程序运行后,我们可以看到如下的图片,led在闪烁,我抓拍了图片:
旁边那个东西就是我的仿真器。