/*
* File: main.c
* Author: bigwater
*
* Created on December 2, 2014, 12:21 AM
*/
#include <stdio.h>
#include <stdlib.h>
#include <pic18.h>
#include <pic18f25k80.h>
#pragma config FOSC = INTIO2 //Internal RC oscillator 选择内部时钟
#pragma config FOSC WDTEN = OFF //WDT disabled in hardware 禁止看门狗
#pragma config FOSC XINST = OFF // Extended Instruction Set Off
#pragma config CONFIG3H = 0X09 //选择内部复位
/*
*
*/
unsigned int temp; //全局变量
void PIC_Init(void)
{
OSCCON|=0X50; //振荡器 4MHz
OSCTUNEbits.PLLEN=0; //禁止4位PLL
PORTA =0X00;
ANCON1 = 0x00;
TRISA = 0xFF; //设置数字输出
TRISA=0X00; //Port A outport 配置Port A 输出
LATA=0X00; // Port A outport low 配置Port A 输出低电平
//TRISB=0X00; //Port B outport 配置Port B 输出
//TRISB = 0xFFFD;
//LATB=0X00; // Port B outport low 配置Port B 输出低电平
//INTCON2bits.nRBPU=1;
}
void timer1_init(void) //4M/4 约为1us
{
T1CON=0X01; //16bit 定时方式
TMR1IF=0; //clear timer1 Int flag
TMR1IE=1; //enable timer1 Int
TMR1H=0xFC; //设置计数器高位
TMR1L=0x26; //设置计数器低位
//约为 1ms 一次中断
PEIE=1 ;//enable peripheral interrupt
GIE=1; //enable global interrupt
}
void interrupt ISR(void)
{
if(TMR1IF==1)
{
TMR1H=0XFC; //重置计数器高位
TMR1L=0x26; //重置计数器低位
TMR1IF=0; //clear time1 interrupt flag
temp++; //中断次数累加
if(temp>499) //500次约为0.5S
{
temp=0; //清零
RA0=!RA0; //PortA 的物理上第一脚 翻转
}
}
}
int main(void)
{
PIC_Init();
timer1_init();
while(1);
return (EXIT_SUCCESS);
}
示波器测不出我的输出脚的波形,请问我哪里写错了么?。新手别喷 |