智能车制作
标题:
pit中断《k10》
[打印本页]
作者:
oneJN
时间:
2012-11-8 18:40
标题:
pit中断《k10》
/*
* main implementation: use this 'C' sample to create your own application
*
*/
#include <stdio.h>
#include "derivative.h" /* include peripheral declarations */
#define GPIO_PIN(x) (((1)<<(x & GPIO_PIN_MASK)))
#define GPIO_PIN_MASK 0x1Fu
#define PORTA PTA_BASE_PTR
#define PORTB PTB_BASE_PTR
#define PORTC PTC_BASE_PTR
#define PORTD PTD_BASE_PTR
#define PORTE PTE_BASE_PTR
typedef unsigned char uint8; /* 8 bits */
typedef unsigned short int uint16; /* 16 bits */
typedef unsigned long int uint32; /* 32 bits */
typedef char int8; /* 8 bits */
typedef short int int16; /* 16 bits */
typedef int int32; /* 32 bits */
void PIT_Init()
{
SIM_SCGC6 |= 0x00800000;
PIT_MCR = 0x00;
PIT_TCTRL0 = 0x00;
PIT_TFLG0 = 0x01;
PIT_LDVAL0 = 10000000;
NVICISER2 |= 0x10;//使能中断NVICISERn=m,其中n=84/32,m=84%32
PIT_TCTRL0 = 0x03;
PIT_TCTRL1 = 0x00;
PIT_TFLG1 = 0x01;
PIT_LDVAL1 = 20000000;
NVICISER2 |= 0x20;//使能中断NVICISERn=m,其中n=85/32,m=85%32, NVICICER0 = 1 << (irq%32);
PIT_TCTRL1 = 0x03;
PIT_TCTRL2 = 0x00;
PIT_TFLG2 = 0x01;
PIT_LDVAL2 = 30000000;
NVICISER2 |= 0x40;//使能中断NVICISERn=m,其中n=86/32,m=86%32
PIT_TCTRL2 = 0x03;
PIT_TCTRL3 = 0x00;
PIT_TFLG3 = 0x01;
PIT_LDVAL3 = 40000000;
NVICISER2 |= 0x80;//使能中断NVICISERn=m,其中n=87/32,m=87%32
PIT_TCTRL3 = 0x03;
}
void gpio_init (GPIO_MemMapPtr port, int32 index, int32 dir, int32 data)//
{
PORT_MemMapPtr p;
/* Turn on all port clocks */
//SIM_SCGC5 = SIM_SCGC5_PORTA_MASK | SIM_SCGC5_PORTB_MASK | SIM_SCGC5_PORTC_MASK | SIM_SCGC5_PORTD_MASK | SIM_SCGC5_PORTE_MASK;
switch((uint32)port)
{
case 0x400FF000u:
p = PORTA_BASE_PTR;
SIM_SCGC5 |= SIM_SCGC5_PORTA_MASK; //开PORTA使能时钟
break;
case 0x400FF040u:
p = PORTB_BASE_PTR;
SIM_SCGC5 |= SIM_SCGC5_PORTB_MASK; //开PORTB使能时钟
break;
case 0x400FF080u:
p = PORTC_BASE_PTR;
SIM_SCGC5 |= SIM_SCGC5_PORTC_MASK; //开PORTC使能时钟
break;
case 0x400FF0C0u:
p = PORTD_BASE_PTR; //((GPIO_MemMapPtr)0x400FF0C0u)
SIM_SCGC5 |= SIM_SCGC5_PORTD_MASK; //开PORTD使能时钟
break;
case 0x400FF100u:
p = PORTE_BASE_PTR;
SIM_SCGC5 |= SIM_SCGC5_PORTE_MASK; //开PORTE使能时钟
break;
default:
break;
}
PORT_PCR_REG(p,index) = (0|PORT_PCR_MUX(1)); //配置PORT口德MUX为为GPIO模式
if(dir == 1) //output
{
GPIO_PDDR_REG(port) |= (1<<index); //配置PORTn口的第index引脚为输出
if(data == 1) //设置输出值
GPIO_PDOR_REG(port) |= (1<<index); //端口输出值为1
else
GPIO_PDOR_REG(port) &= ~(1<<index); //端口输出值为0
}
else //设置为输入口
{
GPIO_PDDR_REG(port) &= ~(1<<index);
if(data == 1) //上拉电阻
PORT_PCR_REG(p,index) |= PORT_PCR_PS_MASK;
else //下拉电阻
PORT_PCR_REG(p,index) &= ~(PORT_PCR_PS_MASK);
PORT_PCR_REG(p,index) |= PORT_PCR_PE_MASK;
}
//GPIO_PDDR_PDD();
//GPIOD_PDDR;
}
* 函数名:gpio_reverse
* 功 能:改变引脚状态
* 参 数: port:端口名
* index:指定端口引脚
* 返 回:无
* 说 明:无
************************************************/
void gpio_reverse(GPIO_MemMapPtr port, int32 index)
{
GPIO_PTOR_REG(port) |= (1<<index); //PTOR,toggle output,输出翻转
}
int main(void)
{
PIT_Init();
gpio_init(PORTD,4,1,1);
while(1)
{;}
}
void pit0_isr(void)
{
//uint32 c;
//PIT_TCTRL0 &= ~(PIT_TCTRL_TEN_MASK|PIT_TCTRL_TIE_MASK);//定时器中断使能 定时器使能
PIT_TFLG0=PIT_TFLG_TIF_MASK;//标志位清除
//GPIOA_PTOR=0X0003E000;//
//c=PIT_CVAL0;
GPIOD_PDDR &= ~GPIO_PDDR_PDD(GPIO_PIN(1));
PIT_LDVAL0 = 5000000; //设置时间 time*系统时钟*1000 50ms
gpio_reverse (PTD_BASE_PTR,4);
}
在向量表中修改中断irq名称的说
我是新手,学K10
作者:
oneJN
时间:
2012-11-8 18:42
//设置时间 time*系统时钟*1000 50ms
这个程序默认系统时钟,未倍频,50ms估计不准
作者:
jiyiboloann
时间:
2012-11-8 20:20
在startup.c文件中有中断向量表,找到对应中断源的中断号,并修改中断服务函数名称。
作者:
yandld
时间:
2013-8-25 10:31
http://www.znczz.com/thread-123546-1-1.html
作者:
yandld
时间:
2013-8-25 10:32
要开PIT内部的中断和 NVIC中断,具体看这里
http://www.znczz.com/thread-123546-1-1.html
欢迎光临 智能车制作 (http://dns.znczz.com/)
Powered by Discuz! X3.2