基于AT89S52的pwm脉宽调制的C语言编程

源代码在线查看: sp0604_实验19_脉宽可调和显示的pwm信号.lst

软件大小: 32 K
上传用户: dsdsads
关键词: 89S S52 pwm AT
下载地址: 免注册下载 普通下载 VIP

相关代码

				C51 COMPILER V8.01   SP0604_实验19_耞宽可礯和显蔩的PWM信号                                 04/06/2006 23:14:24 PAGE 1   
				
				
				C51 COMPILER V8.01, COMPILATION OF MODULE SP0604_实验19_耞宽可礯和显蔩的PWM信号
				OBJECT MODULE PLACED IN SP0604_实验19_脉宽可调和显示的PWM信号.OBJ
				COMPILER INVOKED BY: d:\Keil\C51\BIN\C51.EXE SP0604_实验19_脉宽可调和显示的PWM信号.c BROWSE DEBUG OBJECTEXTEND TABS(2)
				
				line level    source
				
				   1          #include 
				   2          
				   3          
				   4          
				   5          #define KEY_ADD (P3 & 0x04)
				   6          #define KEY_SUB (P3 & 0x08)
				   7          
				   8          
				   9          
				  10          #define PWM P1_0
				  11          unsigned char PWM_High=50;
				  12          unsigned char PWM_Count=0;
				  13          
				  14          
				  15          void timer0(void) interrupt 1
				  16          {
				  17   1        if(PWM_Count				  18   1          else PWM=1;
				  19   1        PWM_Count++;
				  20   1        if(PWM_Count==100)PWM_Count=0;
				  21   1      }
				  22          
				  23          
				  24          const unsigned char LEDDATA[]={0x3f,0x06,0x5b,0x4f,0x66,
				  25                                         0x6d,0x7d,0x07,0x7f,0x6f,
				  26                                         0x77,0x7c,0x39,0x5e,0x79,0x71,
				  27                                        };
				  28          //数码管扫描代码表
				  29          unsigned char code LEDBITDATA[]=
				  30          {
				  31            0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,
				  32          };
				  33          
				  34          #define LEDDATAPORT P0
				  35          #define LEDBITPORT  P2
				  36          unsigned char ScanLedCount;
				  37          unsigned char LEDBuffer[2];
				  38          
				  39          void timer1(void) interrupt 3
				  40          {
				  41   1        TH1=(65536-2000)/256;
				  42   1        TL1=(65536-2000)%256;
				  43   1      
				  44   1        LEDDATAPORT=LEDDATA[LEDBuffer[ScanLedCount]];
				  45   1        LEDBITPORT =LEDBITDATA[ScanLedCount];
				  46   1        ScanLedCount++;
				  47   1        if(ScanLedCount==sizeof(LEDBuffer))ScanLedCount=0;  
				  48   1      }
				  49          
				  50          
				  51          
				  52          void Delay(unsigned int t)
				  53          {
				  54   1        while(t)t--;
				  55   1      }
				C51 COMPILER V8.01   SP0604_实验19_耞宽可礯和显蔩的PWM信号                                 04/06/2006 23:14:24 PAGE 2   
				
				  56          
				  57          
				  58          
				  59          void main(void)
				  60          {
				  61   1        TMOD=0x12;
				  62   1        TH0=256-184;
				  63   1        TL0=TH0;
				  64   1        TH1=(65536-2000)/256;
				  65   1        TL1=(65536-2000)%256;
				  66   1        TR0=1;
				  67   1        TR1=1;
				  68   1        ET0=1;
				  69   1        ET1=1;
				  70   1        EA=1;
				  71   1      
				  72   1        LEDBuffer[0]=PWM_High%10;
				  73   1        LEDBuffer[1]=PWM_High/10;
				  74   1        while(1)
				  75   1          {
				  76   2            if(KEY_ADD==0)
				  77   2              {
				  78   3                Delay(1000);
				  79   3                if(KEY_ADD==0)
				  80   3                  {
				  81   4                    PWM_High--;
				  82   4                    if(PWM_High==0)PWM_High=1;
				  83   4                    LEDBuffer[0]=PWM_High%10;
				  84   4                    LEDBuffer[1]=PWM_High/10;
				  85   4                    while(KEY_ADD==0);
				  86   4                  }
				  87   3              }
				  88   2      
				  89   2            if(KEY_SUB==0)
				  90   2              {
				  91   3                Delay(1000);
				  92   3                if(KEY_SUB==0)
				  93   3                  {
				  94   4                    PWM_High++;
				  95   4                    if(PWM_High==100)PWM_High=99;
				  96   4                    LEDBuffer[0]=PWM_High%10;
				  97   4                    LEDBuffer[1]=PWM_High/10;
				  98   4                    while(KEY_SUB==0);
				  99   4                  }
				 100   3              }
				 101   2          }
				 102   1      }
				
				
				MODULE INFORMATION:   STATIC OVERLAYABLE
				   CODE SIZE        =    242    ----
				   CONSTANT SIZE    =      8    ----
				   XDATA SIZE       =   ----    ----
				   PDATA SIZE       =   ----    ----
				   DATA SIZE        =     21    ----
				   IDATA SIZE       =   ----    ----
				   BIT SIZE         =   ----    ----
				END OF MODULE INFORMATION.
				
				
				C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)
							

相关资源