第一次用PIC的片子,想用PIC12f675实现100KHz的PWM输出,看了下手册算了下应该是可以做1us定时的。但搞了半天最高只能输出15KHz。大家帮忙看看问题出在了哪里?#include<pic12f675.h>
// CONFIG
#pragma config FOSC = INTRCIO // Oscillator Selection bits (INTOSC oscillator: I/O function on GP4/OSC2/CLKOUT pin, I/O function on GP5/OSC1/CLKIN)
#pragma config WDTE = ON // Watchdog Timer Enable bit (WDT enabled)
#pragma config PWRTE = OFF // Power-Up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = OFF // GP3/MCLR pin function select (GP3/MCLR pin function is digital I/O, MCLR internally tied to VDD)
#pragma config BOREN = OFF // Brown-out Detect Enable bit (BOD disabled)
#pragma config CP = OFF // Code Protection bit (Program Memory code protection is disabled)
#pragma config CPD = OFF // Data Code Protection bit (Data memory code protection is disabled)
#define nop() asm("NOP")
#define u8 unsigned char
#define u16 unsigned int
#define PWM_A GPIO2
#define LED GPIO1
u8 n = 0;
void init(void)
{
CMCON = 0x07;
ANSEL = 0x00;
WPU |= 0x20;
TRISIO = 0x38;
TMR0 = 0xFF;
//OPTION_REG
T0CS = 0;
PSA = 1;
//INTCON
T0IF = 0;
T0IE = 1;
GIE = 1;
}
void __interrupt(low_priority) tmer0(void)
{
if(T0IF==1)
{
TMR0 = 0xFF;
T0IF = 0;
n++;
if(n==1)
PWM_A = 1;
else
{
PWM_A = 0;
n = 0;
}
}
}
void main(void)
{
init();
while(1);
}
|