[程序源码] PIC单片机写的交通灯程序

[复制链接]
1082|1
 楼主| IversonCar 发表于 2015-8-27 15:12 | 显示全部楼层 |阅读模式
  1. #include<pic.h>
  2. #include<stdio.h>
  3. #define uint unsigned int
  4. #define uchar unsigned char
  5. uchar H_time=0,L_time=0;
  6. const uchar tab[]={0x0a,0x22,0x11,0x14};
  7. extern uchar code[]={0x00,0x00,0x00,0x00};
  8. void delay(uint z)
  9. {
  10. uint x,y;
  11. for(x=z;x>0;x--)
  12. for(y=5;y>0;y--);
  13. }
  14. void light(uchar n)
  15. {
  16. uchar i,top,temp;
  17. for(;n>0;n--)
  18. {
  19. PORTC=H_time*16+L_time;
  20. H_time++;L_time++;
  21. temp=0x00;
  22. for(i=0;i<0xff;i++)
  23. {
  24. temp++;
  25. PORTD=temp;
  26. delay(2);
  27. }
  28. }
  29. }
  30. void RGB_light()
  31. {
  32. PORTB=tab[0];
  33. light(7);H_time=0x00;
  34. PORTB=tab[1];
  35. light(2);H_time=0x00;L_time=0x00;
  36. PORTB=tab[2];
  37. light(7);L_time=0x00;
  38. PORTB=tab[3];
  39. light(2);H_time=0x00;L_time=0x00;
  40. PORTB=0X00;

  41. }
  42. void main()
  43. {
  44. TRISD=0;
  45. TRISB=0;
  46. TRISC=0;
  47. while(1)
  48. {
  49. RGB_light();
  50. }

  51. }





没钱买硬件,只能虚拟了


舒斯特尔 发表于 2015-8-27 16:01 | 显示全部楼层
这样也是一种好的学习方法啊
您需要登录后才可以回帖 登录 | 注册

本版积分规则

50

主题

344

帖子

0

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