#include <stdio.h>
#include <system.h>
#include <sys/alt_irq.h>
void Display(int speed,int choice)
{
int HEX_ARRAY[]={0xc0,0xf9,0xa4,0xb0,
0x99,0x92,0x82,0xf8,
0x80,0x90};
volatile int* pHEX_30=PIO_HEX_3_0_BASE;
volatile int* pHEX_74=PIO_HEX_7_4_BASE;
int Tempdisplay[4]={0,0,0,0};
int Hexdisplay=0x0;
Tempdisplay[3]=(int)(speed/1000);
Tempdisplay[2]=(int)((speed%1000)/100);
Tempdisplay[1]=((int)(speed/10))%10;
Tempdisplay[0]=speed%10;
Hexdisplay=(HEX_ARRAY[Tempdisplay[3]]<<24)+(HEX_ARRAY[Tempdisplay[2]]<<16)+(HEX_ARRAY[Tempdisplay[1]]<<8)+(HEX_ARRAY[Tempdisplay[0]]);
if(choice)
{
* pHEX_74=Hexdisplay;
}
else
{
* pHEX_30=Hexdisplay;
}
}
void RotaryEncoderInterruptServiceRoutine(void* pContext)
{
/* Previous is static so that it holds the old button *
* positions between calls */
static int Previous = 0;
int Current;
volatile int *pCount;
volatile int* pEncoder = (int*)ROTARYENCODERPIO_BASE;
/* The Context variable holds the current count value */
pCount = (int*)pContext;
/* Read the encoder */
Current = 0x00000007 & *(pEncoder + 0);
/* Clear the interrupt source */
*(pEncoder + 3) = 7;
/* If the spindle switch is pressed, reset the count to zero */
if (0 == (Current & 0x00000001))
{
*pCount = 1500;
}
/* Look for a clockwise rotation */
if ((0 == (Current & 0x00000006)) && (4 == (Previous & 0x00000006)))
{
(*pCount)=(*pCount)+5;
}
/* Look for an anti clockwise rotation */
if ((0 == (Current & 0x00000006)) && (2 == (Previous & 0x00000006)))
{
(*pCount)=(*pCount)-5;
}
/* Update the previous value to match the current input */
Previous = Current;
Display(*pCount,1);
}
int main()
{
int set_speed,practical_speed;/*theoreticalspeed, practical speed*/
set_speed=1500;
int* p_fan=(int*)FANPIO_BASE;
int* p_encoder=(int*)ROTARYENCODERPIO_BASE;
int* p_timer=(int*)TIMER_0_BASE;
int* p_hex30=(int*)PIO_HEX_3_0_BASE;
int* p_hex74=(int*)PIO_HEX_7_4_BASE;
alt_ic_isr_register (
ROTARYENCODERPIO_IRQ_INTERRUPT_CONTROLLER_ID, /* The ID of the interrupt controller */
ROTARYENCODERPIO_IRQ, /* The IRQ number */
RotaryEncoderInterruptServiceRoutine, /* The interrupt service routine */
(void*)(&set_speed), /* Context information to pass to the ISR */
NULL /* Flags (not used but reserved) */
);
/*allow the keys to generate interrupts*/
*(p_encoder+2) = 7;
int pwm,i;
while(1)
{
*p_fan=2
}
return 1;
}
hello_world.rar_fpga风扇_world_风扇控制
版权申诉
196 浏览量
2022-09-23
13:41:02
上传
评论
收藏 1KB RAR 举报
刘良运
- 粉丝: 68
- 资源: 1万+