📄 pwm.c
字号:
#include <REG1210.H>
#include <intrins.h>
#include <stdio.h>
#include "ISD51.H"
#include "ROM.H"
#define XTAL 11059200
#define BAUDRATE 9600
#define T2RELOAD (65536-(XTAL/32/BAUDRATE))
sbit GreenLed = P2^4;
void delay(void){
unsigned long s;
s =0x0f000;
while(s--);
}
void main(void) {
//Config ISD
T2CON = 0x34; // Use Timer 2 as baudrate generator
RCAP2H = 0xFF;
RCAP2H = (T2RELOAD >> 8); // baudrate reload factor
RCAP2L = T2RELOAD;
SCON0 = 0x50; // enable serial uart & receiver
PCON |= 0x80; // double baudrate for UART0
P3DDRL &= 0xF0; // P3DDRL set port pins of UART0 to input/strong drive output
P3DDRL |= 0x07; // P3DDRL set port pins of UART0 to input/strong drive output
USEC = ((XTAL+500000)/1000000)-1; // USEC timer factor
ONEMS = (XTAL/1000)-1; // (MSECH+MSCL) MS Timer counting at 1.0ms
HMSEC = 100-1; // Hundred MS Timer to 100.0ms
SECINT = (10-1) | 0x80; // SECINT= 10 * HMS Timer Rate = 1 sec
// '0x80' will set the MSB for write immediate
MSINT = (10-1) | 0x80; // MSINT = 10ms for Tone period time base
PDCON = 0x1D; // Powerup SysTimer
FTCON = 0xA5; // setup flash programming times
EICON = 0x40; //DIS enable all auxiliary interrupts
EA = 1; //DIS Enable global interrupt flag
ISDwait (); // wait for connection to uVision2 Debugger
//Config PWM
P3 = 0xFF ; //Config P3's PWM
P3DDRL = 0x40;
PDCON &= 0xED; //Turn on PWM power
PWMCON =0 ; //Config period time
PWM = 200;
PWMCON = 0x10; //Config pwmduty
PWM = 20;
PWMCON = 0x01; //Select time speed using USEC,permit pwm function
while (1) {
printf("Hello World\n");
PWMCON = 0x10;
PWM = 150 ;
PWMCON = 0x01; //Select time speed using USEC,permit pwm function
delay();
PWMCON = 0x10;
GreenLed = 0; //调试指示灯
PWM = 10;
PWMCON = 0x01; //Select time speed using USEC,permit pwm function
delay();
GreenLed = 1;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -