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

📄 main.c

📁 冷火MCF52255开发板精华资料
💻 C
字号:
/*广州穗佳电子科技有限公司
  冷火MCF52255多功能开发板
  更多精彩产品,关注穗佳电子淘宝店
  http://sogadz.taobao.com*/
#include "support_common.h" /* include peripheral declarations and more */
#if (CONSOLE_IO_SUPPORT || ENABLE_UART_SUPPORT) 
/* Standard IO is only possible if Console or UART support is enabled. */
#include <stdio.h>
#endif

#include "PIT.h"


#define uchar unsigned char 
#define uint unsigned int 




/*********************************************/  //延时     /*********************************************/
void delay(int xms)        //xms毫秒延时
{
    int ii,jj;
    
    for(ii=0;ii<xms;ii++)
    for(jj=0;jj<2000;jj++); 
       
}
void delay_us(int xus)     //xus微秒延时
{
    int ii,jj;
    
    for(ii=0;ii<xus;ii++)
    for(jj=0;jj<2;jj++);    
}

/*********************************************/  //流水灯,数码管 蜂鸣器 /*********************************************/



#define Du MCF_GPIO_PORTUC_PORTUC0 	//段选锁存器控制端
#define We MCF_GPIO_PORTUC_PORTUC1 	//位选锁存器控制端

#define Du_1 MCF_GPIO_PORTUC|=Du 	//段选锁存器控制端置1
#define We_1 MCF_GPIO_PORTUC|=We 	//位选锁存器控制端置1

#define Du_0 MCF_GPIO_PORTUC&=~Du 	//段选锁存器控制端置0
#define We_0 MCF_GPIO_PORTUC&=~We 	//位选锁存器控制端置0


void IO_init() 
{
   
    MCF_GPIO_PTJPAR = 0x00;      // 配置PTJ为普通IO    
    MCF_GPIO_DDRTJ = 0xff;    // 设置PTJ为输出
    MCF_GPIO_PORTTJ = 0x00;   //关闭PTJ口
    
    MCF_GPIO_PUCPAR = 0x00;      // 配置PUC为普通IO    
    MCF_GPIO_DDRUC = 0xff;    	// 设置PUC为输出
    MCF_GPIO_PORTUC = 0x08;      //关闭PUC口
    
}


uchar num_we[]={0x87,0x8b,0x8d,0x8e,};//数码管位控制
uchar num_du[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x80};//数码管段码表
void Segment_clr()
{
	MCF_GPIO_PORTTJ=0x00;		//消影
	Du_1;		//段选锁存器
	Du_0;
}
void Seg_1(uchar n,uchar m)//第n位显示数m
{
	MCF_GPIO_PORTTJ=0x00;		//消影
	Du_1;		//段选锁存器
	Du_0;
	
	MCF_GPIO_PORTTJ=num_we[n];	//位选信号
	We_1;		//位选锁存器
	We_0;
	
	MCF_GPIO_PORTTJ=m;	//段选信号
	Du_1;		//段选锁存器
	Du_0;	
	
}

void Segment_4(uint m)//显示数m
{
	Seg_1(0,num_du[m%10]);
	Seg_1(1,num_du[m/10%10]);
	Seg_1(2,num_du[m/100%10]);
	Seg_1(3,num_du[m/1000%10]);
	
}

/**********************************************************************************************************
**********************************************************************************************************/

uint con_PIT;



	
void main(void) 
{
	
	int counter;
	int i=0,j=0,k=0;

    IO_init();

    


   

	//******************  数码管 PIT ******************
	PIT0_init();
	EnableInterrupts;	
	PIT0_start(78125);
	while(1) 
  	{ 
  	
 		Segment_4(con_PIT);
 	
  	}

    
} 


⌨️ 快捷键说明

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