红外发射求助
2024-6-30 20:04 来自 呵呵哥 发布 @ 综合讨论
- #ifndef STC8_H
 
- #define STC8_H
 
- #include <STC8G.H>
 
- #endif
 
- #include<intrins.h>
 
 
- #include "Timer0.h"
 
- //以12MHZ烧录
 
- void Delay3000ms(void)        //@11.0592MHz
 
- {
 
-         unsigned char data i, j, k;
 
 
-         _nop_();
 
-         i = 169;
 
-         j = 80;
 
-         k = 87;
 
-         do
 
-         {
 
-                 do
 
-                 {
 
-                         while (--k);
 
-                 } while (--j);
 
-         } while (--i);
 
- }
 
 
 
 
 
 
- void main()
 
- {
 
-             P5M0 |= 0x10; P5M1 &= ~0x10; 
 
-                         Timer0_Init();
 
-                         P54 = 0;
 
-                         while(1)
 
-                         {
 
-                         
 
-                                 SendCode(0xfc,0xAf);//1111 1100 0110 1001
 
-                                 Delay3000ms();
 
-                         }
 
- }
- #ifndef STC8_H
 
- #define STC8_H
 
- #include <STC8G.H>
 
- #endif
 
 
- bit OP=0;                                   //红外发射管的亮灭控制位
 
- unsigned int count =0;                //载波发射时间
 
- unsigned int Lcount =0;        //发射载波后,等待的时间
 
 
- void Timer0_Init(void)                //26微秒@12.000MHz
 
- {
 
-         AUXR &= 0x7F;                        //定时器时钟12T模式
 
-         TMOD &= 0xF0;                        //设置定时器模式
 
-         TL0 = 0xE6;                                //设置定时初始值
 
-         TH0 = 0xFF;                                //设置定时初始值
 
-         TF0 = 0;                                //清除TF0标志
 
-         TR0 = 1;                                //定时器0开始计时
 
-         ET0 = 1;
 
-         EA = 1;
 
- }
 
- void SendSingleCode(unsigned char _code)
 
- {
 
-         while (Lcount>0);//直到当前不在发射数据
 
-         switch (_code)
 
-         {
 
-         case 0://560/26=21.6,560/26=21.6
 
-                 count = 22;
 
-                 Lcount = 22;
 
- brea
- 最近查阅:
免责声明:
本平台旨在开源共享精神,请勿发布敏感信息,任何违法信息我们将移交公安机关;


