完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
本帖最后由 HelloWii 于 2015-9-21 08:51 编辑
实验一:流水灯 程序都是在AVR Studio上完成的
|
|
相关推荐
5 个讨论
|
|
实验二:键盘扫描
//----------------------------------------------------------------------- //说明;键盘扫描,,矩阵键盘 // // //------------------------------------------------------------------------ #define F_CPU 8000000 #include"avr/io.h" #include"util/delay.h" #include"avr/pgmspace.h" #define uchar unsigned char #define uint unsigned int #define DDRx_KEY DDRD #define PINx_KEY PIND #define PORTx_KEY PORTD uchar Get_Key()//有返回值的函数 { uchar temp=0,temp1,temp2; uchar KEY_Number; unsigned char i; DDRx_KEY =0x0F;//定义PD0-PD3为输入,PD4-PD7为输出 PORTx_KEY =0xF0;// asm("nop");// if((PINx_KEY&0xF0)!=0xF0) { _delay_ms(5); if((PINx_KEY&0xF0)!=0xF0) { for(i=0;i<4;i++) { temp1 =~(1< PORTx_KEY =temp1; asm("nop");//一定得加!也可加小延时。 if((PINx_KEY & 0xF0)!=0xF0) { temp2=PINx_KEY; temp=(temp1 & 0x0F)+(temp2 & 0xF0); } } } } switch(temp) { case 0xEE: KEY_Number=0; break; case 0xDE: KEY_Number=1; break; case 0xBE: KEY_Number=2; break; case 0x7E: KEY_Number=3; break; case 0xED: KEY_Number=4; break; case 0xDD: KEY_Number=5; break; case 0xBD: KEY_Number=6; break; case 0x7D: KEY_Number=7; break; case 0xEB: KEY_Number=8; break; case 0xDB: KEY_Number=9; break; case 0xBB: KEY_Number=10; break; case 0x7B: KEY_Number=11; break; case 0xE7: KEY_Number=12; break; case 0xD7: KEY_Number=13; break; case 0xB7: KEY_Number=14; break; case 0x77: KEY_Number=15; break; default: KEY_Number=255; break; } return KEY_Number; } const prog_char SegCode[16]={ /* Cathode common Smg display code*/ 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; uchar DisBuffer[8]={0,0,0,0,0,0,0,0}; void Scanf(void) { unsigned char i=0; for(i=0;i<8;i++) { PORTB = pgm_read_byte(&SegCode[DisBuffer[i]]); PORTA|= (1< PORTB = ~(1< PORTA|= (1< _delay_ms(2); } } int main(void) { uchar KeyNumber=0; /* Set LED and Smg LE pin and USB-pull-up pin as output , databus as output */ DDRA |=(1< /* Off the LED display */ PORTB = 0xFF; PORTA|= (1< { KeyNumber=Get_Key();//Get_Key()是一个值 if(KeyNumber!=255) DisBuffer[7]=KeyNumber; Scanf(); } return 0; } |
|
|
|
|
|
实验三:外部中断
#define F_CPU 8000000 #include "avr/io.h" #include "util/delay.h" #include "avr/pgmspace.h" #include "avr/interrupt.h" const prog_char SegCode[16]={ 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; unsigned char DisBuffer[8]; volatile unsigned int Count=0; void delay_ms(unsigned int ms) { while(ms--) _delay_ms(1); } void Scanf(void) { unsigned char i=0; for(i=0;i<8;i++) { PORTB = pgm_read_byte(&SegCode[DisBuffer[i]]); PORTA|= (1< PORTB = ~(1< PORTA|= (1< _delay_ms(2); } } void IntInit(void) { PORTD|= (1< } int main(void) { /* Set LED and Smg LE pin as output , databus as output */ DDRA |=(1< /* Off the LED display */ PORTB = 0xFF; PORTA|= (1< IntInit(); while(1) { DisBuffer[0]=0; DisBuffer[1]=0; DisBuffer[2]=0; DisBuffer[3]=Count/10000%10; DisBuffer[4]=Count/1000%10; DisBuffer[5]=Count/100%10; DisBuffer[6]=Count/10%10; DisBuffer[7]=Count/1%10; Scanf(); } return 0; } SIGNAL(INT0_vect) { GIFR&=~(1< Count++; } } SIGNAL(INT1_vect) { GIFR&=~(1< Count--; } } |
|
|
|
|
|
{:3:}
|
|
|
|
|
|
只有小组成员才能发言,加入小组>>
AVR Atmega16 Bootloader程序与上位机LabView程序
5122 浏览 6 评论
#include <ioavr.h>这个头文件我应该下什么编译器
7767 浏览 0 评论
3026 浏览 2 评论
3103 浏览 1 评论
10053 浏览 1 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-24 08:51 , Processed in 0.867209 second(s), Total 55, Slave 43 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号