|
程序目的是實(shí)現(xiàn)上電燈就亮”輸出1“ 定時(shí)后”輸出0“
#include<pic.h>
#include <xc.h>
#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 = OFF // Watchdog Timer Enable bit (WDT disabled)
#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 KEY GP3
unsigned char count=0;
unsigned char miao=0;
unsigned char fen=0;
void main()
{
OSCCAL=0b00000100;//intside RC
TRISIO=0b00001000;//IO方向設(shè)置
OPTION_REG=0b00000111;//分頻比1:256
TMR0=0;
GP0=1;
// GP1=GP2=GP4=GP5=0; 寫進(jìn)這行燈就一直不亮,不寫就是正常的
while(1)
{
if(TMR0==180)//50ms
{
TMR0=0;
count++;
if(count==20)//1秒定時(shí)
{
miao++;
count=0;
if(miao==5)
{
miao=0;
GP0=0;
}
}
}
}
}
|
|