[Atmel] 用AtmelStudio6.2跑mega16例程(55)74HC595

[复制链接]
985|0
 楼主| ddllxxrr 发表于 2014-11-17 21:48 | 显示全部楼层 |阅读模式
74HC595是串转并芯片。它的特点是锁存数据,所以用它来驱动LED没有闪炼感。

以下是Proteus运行的载图:


Stduio6.2编译通过的结果。


程序清单:
  1. /*
  2. * GccApplication18.c
  3. *
  4. * Created: 2014-11-17 21:03:06
  5. *  Author: Administrator
  6. */

  7. #define  F_CPU 1000000UL
  8. #include <avr/io.h>
  9. #include <util/delay.h>
  10. #include <stdint.h>

  11. //管脚定义

  12. #define SH_CP PC0
  13. #define DS PC1
  14. #define SP_CP PC3

  15. #define SH_CP_0() PORTC &= ~_BV(SH_CP)
  16. #define SH_CP_1() PORTC |= _BV(SH_CP)
  17. #define DS_0() PORTC &= ~_BV(DS)
  18. #define DS_1() PORTC |=_BV(DS)
  19. #define ST_CP_0() PORTC &=~_BV(SP_CP)
  20. #define ST_CP_1() PORTC |= _BV(SP_CP)

  21. const uint8_t SEG_CODE[] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};

  22. void Serial_Input_595(uint8_t dat)
  23. {
  24.         uint8_t i;
  25.         for(i = 0;i<8;i++)
  26.         {
  27.             if(dat & 0x80) DS_1(); else DS_0();
  28.                 dat <<= i;
  29.                 SH_CP_0(); _delay_us(2);
  30.                 SH_CP_1(); _delay_us(2);
  31.                 SH_CP_0(); _delay_us(2);
  32.                
  33.         }
  34. }

  35. void Paraller_Output_595()
  36. {
  37.         ST_CP_0(); _delay_us(1);
  38.         ST_CP_1(); _delay_us(1);
  39.         ST_CP_0(); _delay_us(1);
  40. }



  41. int main(void)
  42. {
  43.     uint8_t i=0;
  44.         DDRC = 0xFF;
  45.         while(1)
  46.     {
  47.        for(i = 0;i<10;i++)
  48.            {
  49.                 Serial_Input_595(SEG_CODE[i]);
  50.                         Paraller_Output_595();
  51.                         _delay_ms(300);
  52.            }
  53.             //TODO:: Please write your application code
  54.     }
  55. }

本帖子中包含更多资源

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

×
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:http://shop34182318.taobao.com/ http://shop562064536.taobao.com

2404

主题

7002

帖子

68

粉丝
快速回复 在线客服 返回列表 返回顶部