⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 SmartARM2200开发平台光盘资料中的所有的源码和测试程序以及应用程序
💻 C
字号:
/****************************************Copyright (c)**************************************************
**                               Guangzou ZLG-MCU Development Co.,LTD.
**                                      graduate school
**                                 http://www.zlgmcu.com
**
**--------------File Info-------------------------------------------------------------------------------
** File name:			main.c
** Last modified Date:  2004-09-16
** Last Version:		1.0
** Descriptions:		The main() function example template
**
**------------------------------------------------------------------------------------------------------
** Created by:			Ganda
** Created date:		2005-4-22
** Version:				1.0
** Descriptions:		The original version
**
**------------------------------------------------------------------------------------------------------
** Modified by:			Chenxibing
** Modified date:		2005-02-19
** Version:
** Descriptions:		
**
********************************************************************************************************/
#include "config.h"
#include <math.h>
#define CAT1025 0xA0
#define PI 3.1415


uint16 i,j,k;
int32  time = 100;

uint16 wave[512];

void I2C_IntInit(void);
void RTC_IntInit(void);


int main (void)
{   
    GPIO_Init();
    UART0_Init();
    RTC_Init();
    MSPI_Init();
    I2C_Init(400000);

    I2C_IntInit();
    RTC_IntInit();
    IRQEnable();	

sin: 
    IO1SET = 0xffffffff;
    IO1CLR = LED1;
    while(1)
    {
        i=i+8;
        if(i == 512) i = 0;
        DACR = sinwave[i] << 8;
        for(j=0; j<time; j++);
        if( (IO0PIN & 0x3F0000) != 0x3F0000 )
        {
            if( (IO0PIN & KEY1) == 0 ) 
                goto sin;
            if( (IO0PIN & KEY2) == 0 ) 
                goto saw;
            if( (IO0PIN & KEY3) == 0 ) 
                goto tri;   
            if( (IO0PIN & KEY4) == 0 ) 
                goto squ;   
            if( (IO0PIN & KEY5) == 0 ) 
                goto inc;  
            if( (IO0PIN & KEY6) == 0 ) 
                goto dec;  
        }
    }
    
saw:
    IO1SET = 0xffffffff;
    IO1CLR = LED2;
    while(1)
    {
 
        i=i+8;
        if(i == 512) i = 0;
        DACR = sawwave[i] << 8;
        for(j=0; j<time; j++);
        if( (IO0PIN & 0x3F0000) != 0x3F0000 )
        {
            if( (IO0PIN & KEY1) == 0 ) 
                goto sin;
            if( (IO0PIN & KEY2) == 0 ) 
                goto saw;
            if( (IO0PIN & KEY3) == 0 ) 
                goto tri;   
            if( (IO0PIN & KEY4) == 0 ) 
                goto squ;   
            if( (IO0PIN & KEY5) == 0 ) 
                goto inc;  
            if( (IO0PIN & KEY6) == 0 ) 
                goto dec;  
        }
    }
    
    
tri:
    IO1SET = 0xffffffff;
    IO1CLR = LED3;
    while(1)
    {
        i=i+8;
        if(i == 512) i = 0;
        DACR = triwave[i] << 8;
        for(j=0; j<time; j++);
        if( (IO0PIN & 0x3F0000) != 0x3F0000 )
        {
            if( (IO0PIN & KEY1) == 0 ) 
                goto sin;
            if( (IO0PIN & KEY2) == 0 ) 
                goto saw;
            if( (IO0PIN & KEY3) == 0 ) 
                goto tri;   
            if( (IO0PIN & KEY4) == 0 ) 
                goto squ;   
            if( (IO0PIN & KEY5) == 0 ) 
                goto inc;  
            if( (IO0PIN & KEY6) == 0 ) 
                goto dec;  
        }
    }
    
    
squ:
    IO1SET = 0xffffffff;
    IO1CLR = LED4;
    while(1)
    {
        i=i+8;
        if(i == 512) i = 0;
        DACR = squwave[i] << 8;
        for(j=0; j<time; j++);
        if( (IO0PIN & 0x3F0000) != 0x3F0000 )
        {
            if( (IO0PIN & KEY1) == 0 ) 
                goto sin;
            if( (IO0PIN & KEY2) == 0 ) 
                goto saw;
            if( (IO0PIN & KEY3) == 0 ) 
                goto tri;   
            if( (IO0PIN & KEY4) == 0 ) 
                goto squ;   
            if( (IO0PIN & KEY5) == 0 ) 
                goto inc;  
            if( (IO0PIN & KEY6) == 0 ) 
                goto dec;  
        }
    }
    
inc:
    time++;
    if(time<150) 
    {
        DelayNS (5);
        IO0CLR = BEEP;
        DelayNS (5);
        IO0SET = BEEP;
        MSPI_SendData(DISP_TAB[(uint8)10*time/150]);
    }
    else
    {
        time = 150;
    }
    goto squ;
dec:
    time--;
    if(time > 1) 
    {
        DelayNS (5);
        IO0CLR = BEEP;
        DelayNS (5);
        IO0SET = BEEP;
        MSPI_SendData(DISP_TAB[(uint8)10*time/150]);
    }
    else
    {
        time = 0;
    }
    goto squ;
}
    

/*
            for(i=0; i<512; i++)
            {
                wave[i] = (sinwave[i]+triwave[i]) << 1;
            }

            for(i=0; i<512; i++)
            {   
                x = -PI + 2*PI*i/512;
                y = (uint16)(512*( sin(x) + (sin(3*x))/3 + (sin(5*x))/5 + (sin(7*x))/7 + (sin(9*x))/9 ) + 511);
                wave[i] = (uint16)y;
            }
*/


void RTC_IntInit(void)
{
    /* 打开RTC中断(使用向量中断) */
	VICIntSelect   = 0x00000000;				// 设置所有中断分配为IRQ中断
	VICVectCntl1   = 0x20 | 13;					// RTC通道分配到IRQ slot1
	VICVectAddr1   = (uint32)RTC_Int;			// 设置中断服务程序地址
	ILR 		   = 0x03;						// 清除RTC中断标志
	VICIntEnable   = 1 << 13;					// 使能RTC中断
}

void I2C_IntInit(void)
{
	/* 设置I2C中断允许 */
	VICIntSelect = 0x00000000;							// 设置所有通道为IRQ中断 		
	VICVectCntl0 = (0x20 | 0x09);						// I2C通道分配到IRQ slot0,最高优先级
	VICVectAddr0 = (uint32)IRQ_I2C;						// 设置I2C中断向量 				
	VICIntEnable = (1 << 9);							// 使能I2C中断 					
}







/**********************************************************************************************************
**                            End Of File
********************************************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -