找回密码
 注册会员
img_loading
智能检测中
更新自动建库工具PCB Footprint Expert 2024.04 Pro / Library Expert 破解版

请各位 高手看看我atmega64与MAX7221的程序哪不对,谢谢各位

[复制链接]
admin 发表于 2012-8-24 12:28:27 | 显示全部楼层 |阅读模式

本文包含原理图、PCB、源代码、封装库、中英文PDF等资源

您需要 登录 才可以下载或查看,没有账号?注册会员

×
看这个论坛氛围很好,在别处问过的问题再问一遍。

小弟谢了atmega64与max7221的程序,在板子上实验,LED不亮,请各位大神老师指点下哪有错误,谢谢各位。
程序如下

  1. #include <AVR/io.h>
  2. #define uint unsigned int
  3. #define uchar unsigned char
  4. void SPI_MasterInit(void);
  5. void LedDisPlay(uchar addr,uint data);
  6. void Max7221Init(void);
  7. void Write_TUBE( void);
  8. uchar num;
  9. uint TUBE[10]={0,1,2,3,4,5,6,7,8,9}; //缓存数码管的十位数据
  10. //spi初始化
  11. void SPI_MasterInit(void)
  12. {
  13. DDRB =(1<<DDB0)|(1<<DDB1)|(1<<DDB2);
  14. SPCR =(0<<SPIE)|(1<<SPE)|(0<<DORD)|(1<<MSTR)|(0<<CPOL)|(0<<CPHA)|(0<<SPR1)|(1<<SPR0);
  15. }
  16. void Max7221Init(void)
  17. {
  18. LedDisPlay(0x0c,0x01); //工作模式地址 0x0c(0x00:关闭,0x01:正常)
  19. LedDisPlay(0x09,0xff); //解码模式地址 0x09(0x00 为不解码,0xff 为全解码)
  20. LedDisPlay(0x0a,0x07); // 亮度地址0x0a(0x00~0x0f,0x0f 最亮)
  21. LedDisPlay(0x0b,0x07); // 扫描数码管个数地址0x0b(0x07 为扫描数码管0~7)
  22. }
  23. void LedDisPlay(uchar addr,uint data)
  24. {
  25. PORTB &= ~(1<<PB0);
  26. SPDR = addr;
  27. while(!(SPSR & (1<<SPIF)));
  28. SPDR = data;
  29. while(!(SPSR & (1<<SPIF)));
  30. PORTB |= (1<<PB0);
  31. }
  32. //将 TUBE[10] 中数据写入数码管
  33. void Write_TUBE( )
  34. {
  35. uint i;
  36. for(num=0;num<=9;num++)
  37. {
  38. LedDisPlay(num,TUBE[num-1]);
  39. for(i=0;i<=100;i++)
  40. {
  41. //NOP;
  42. }
  43. }
  44. }
  45. /************************主程序*****************************/
  46. int main()
  47. {
  48. DDRB =(1<<PB0)|(1<<PB1)|(1<<PB2);
  49. SPI_MasterInit();
  50. Max7221Init();
  51. Write_TUBE();
  52. while(1);
  53. }
  54. 复制代码
复制代码
您需要登录后才可以回帖 登录 | 注册会员

*滑块验证:
img_loading
智能检测中
本版积分规则

QQ|手机版|MCU资讯论坛 ( 京ICP备18035221号-2 )|网站地图

GMT+8, 2025-7-8 04:41 , Processed in 0.085222 second(s), 9 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表