【嵌入式系统应用】实验关键问题,以及关键代码

版权声明:本文为博主原创文章。转载请联系博主授权。博主微信公众号【知行校园汇】。 https://blog.csdn.net/cxh_1231/article/details/89716121
  • 说明:这是武汉理工大学计算机学院【嵌入式系统应用A】课程:实验关键问题,以及关键代码
  • >>点击查看WUTer计算机专业实验汇总
  • 谨记:纸上得来终觉浅,绝知此事要躬行。

关键问题1:

问题:假设4led灯从下到上对应4位二进制的第0,1,2,3位,灯亮为1,灯灭为0;比如40100)则第2位对应灯亮,30011)则第0,1位对应灯亮;因为0为全灭,若是0则显示为全亮;循环显示你学号的后六位,并把寄存器赋值改为单独赋值。

代码:

#include "s5pc210.h"
#include "uart.h"

/*****************************************************************************
// Function name	: delay
// Description	    : 延时子程序
// Return type		: void
// Argument         : count,延时的数值
*****************************************************************************/
void delay( int count )
{
	int cnt;

	for( count = count; count>0; count--)
		for( cnt = 0; cnt < 1000; cnt++);
}

int main()
{
	uart_init();

	printf("CVT S5PV210 Jtag GpioLed Test...\n");

	volatile int i,j=0;
	GPH3.GPH3CON = 0x11110000;
	int k=0;
	while(1){

		GPH3.GPH3DAT = 0xFF;//全灭
		for(i = 0; i <= 2000000; i++);

		//显示8::1000
		GPH3.GPH3DAT = ~(0x1<<(0+4));
		for(i = 0; i <= 2000000; i++);

		//显示7::0111
		k=0;
		while(1){
			GPH3.GPH3DAT = ~(0x1<<(1+4));
			delay(1);
			GPH3.GPH3DAT = ~(0x1<<(2+4));
			delay(1);
			GPH3.GPH3DAT = ~(0x1<<(3+4));
			delay(1);
			k++;
			if(k==750)
				break;
		}

		//显示0::0000
		GPH3.GPH3DAT = 0xFF;//全灭
		for(i = 0; i <= 2000000; i++);

		//显示9::1001
		k=0;
		while(1){
			GPH3.GPH3DAT = ~(0x1<<(0+4));
			delay(1);
			GPH3.GPH3DAT = ~(0x1<<(3+4));
			delay(1);
			delay(1);
			k++;
			if(k==750)
				break;
		}

		//显示8::1000
		GPH3.GPH3DAT = ~(0x1<<(0+4));
		for(i = 0; i <= 2000000; i++);


		//显示4::0100
		GPH3.GPH3DAT = ~(0x1<<(1+4));
		for(i = 0; i <= 2000000; i++);

		GPH3.GPH3DAT = 0x0;//全亮
		for(i = 0; i <= 2000000; i++);

		//for(j = 0;j<4;j++){
		//	GPH3.GPH3DAT = ~(0x1<<(j+4));
		//	for(i = 0; i <= 1000000; i++);
		//}
	}
	return 0;
}

关键问题2:

问题:

  1. 循环显示你学号的后六位(在第X个数码管上显示你学号后六位的第x位,比如你的学号后六位为012345,则在最左边数码管显示0,最右边显示5,并循环显示

  1. 进阶:静止显示你学号的后六位(012345

代码: 

#include "s5pc210.h"
#include "uart.h"


#define U8 unsigned char
unsigned char seg7table[16] = {
    /* 0       1       2       3       4       5       6      7*/

    0xc0,   0xf9,   0xa4,   0xb0,   0x99,   0x92,   0x82,   0xf8,

    /* 8       9      A        B       C       D       E      F*/
    0x80,   0x90,   0x88,   0x83,   0xc6,   0xa1,   0x86,   0x8e,
};

/*****************************************************************************
// Function name	: delay
// Description	    : 延时子程序
// Return type		: void
// Argument         : count,延时的数值
*****************************************************************************/
void delay( int count )
{
	int cnt;

	for( count = count; count>0; count--)
		for( cnt = 0; cnt < 1000; cnt++);
}

int main()
{
	uart_init();

	printf("CVT S5PV210 Jtag Seg Test...\n");

	int i,j=0;

	*((U8*) 0x88007000) = 0x00;

	for( ; ; )	{
		*((U8*) 0x88007000) = ~(0x1<<j++);
		*((U8*) 0x88009000) = seg7table[8];
		delay (1000);
		//delay (1);

		*((U8*) 0x88007000) = ~(0x1<<j++);
		*((U8*) 0x88009000) = seg7table[7];
		delay (1000);
		//delay (1);

		*((U8*) 0x88007000) = ~(0x1<<j++);
		*((U8*) 0x88009000) = seg7table[0];
		delay (1000);
		//delay (1);

		*((U8*) 0x88007000) = ~(0x1<<j++);
		*((U8*) 0x88009000) = seg7table[9];
		delay (1000);
		//delay (1);

		*((U8*) 0x88007000) = ~(0x1<<j++);
		*((U8*) 0x88009000) = seg7table[8];
		delay (1000);
		//delay (1);

		*((U8*) 0x88007000) = ~(0x1<<j++);
		*((U8*) 0x88009000) = seg7table[4];
		delay (1000);
		//delay (1);

		j=0;
		int k=0;
		for(;;){

			*((U8*) 0x88007000) = ~(0x1<<j++);
			*((U8*) 0x88009000) = seg7table[8];
			//delay (1000);
			delay (1);
			*((U8*) 0x88007000) = ~(0x1<<j++);
			*((U8*) 0x88009000) = seg7table[7];
			//delay (1000);
			delay (1);
			*((U8*) 0x88007000) = ~(0x1<<j++);
			*((U8*) 0x88009000) = seg7table[0];
			//delay (1000);
			delay (1);
			*((U8*) 0x88007000) = ~(0x1<<j++);
			*((U8*) 0x88009000) = seg7table[9];
			//delay (1000);
			delay (1);
			*((U8*) 0x88007000) = ~(0x1<<j++);
			*((U8*) 0x88009000) = seg7table[8];
			//delay (1000);
			delay (1);
			*((U8*) 0x88007000) = ~(0x1<<j++);
			*((U8*) 0x88009000) = seg7table[4];
			//delay (1500);
			delay (1);
			k++;
			j=0;
			if(k==500){
				break;
			}
		}
		/* 数码管从0到F依次将字符显示出来 */
	    //for(i=0;i<0x10;i++)		{
			/* 查表并输出数据 */
	    //	*((U8*) 0x88009000) = seg7table[i];
	    //	delay (1000);
   		//}

		/* 数码管从F到0依次将字符显示出来 */
		//for(i=0xf;i>=0x0;i--)		{
	   		/* 查表并输出数据 */
	   	//	*((U8*) 0x88009000) = seg7table[i];
	   	//	delay (1000);

	 	//}
	 }
	return 0;
}

关键问题3:

问题:

  1. 输入你的姓名全拼的大写变小写,输入你的姓名全拼小写变大写

代码;

#include "s5pc210.h"
#include "uart.h"

/*****************************************************************************
// Function name	: delay
// Description	    : 延时子程序
// Return type		: void
// Argument         : count,延时的数值
*****************************************************************************/
void delay( int count )
{
	int cnt;

	for( count = count; count>0; count--)
		for( cnt = 0; cnt < 1000; cnt++);
}

int main()
{
	uart_init(115200);
	Uart_Select(2);

	printf("姓名全拼大小写互换\n");

	int i=0;
	while(1){
		unsigned char ch = 'a';

		if(i==0){
			printf("a→A\n");//
		}
		if(i==10)//这是因为笔者的姓名只有10个字母,输入完成小写10个后,自动提示输入大写,可换。
			printf("\nA→a\n");
		i++;

		ch = Uart_Getch();


		if(0x41<=ch && ch<= 0x5a ){//小写转换成大写
			Uart_SendByte(ch+32);
		}
		else if(0x61<=ch && ch<= 0x7a ){//大写转换成小写
			Uart_SendByte(ch-32);
		}
		//else if(ch == 0x0d)
		//	Uart_SendByte(0x0a);

		//Uart_SendByte(ch+1);
		//if(ch == 0x0d)
		//	Uart_SendByte(0x0a);
	}
}

结果:

猜你喜欢

转载自blog.csdn.net/cxh_1231/article/details/89716121