EasyArm-i.mx280a开发板入门-AP-283扩展数码管显示(WSL+ubuntu20.04)

1.代码:参看(【AWorks试用体验】动态扫描4位数码管 - NXP MCU 技术论坛 - 电子技术论坛 - 广受欢迎的专业电子论坛!

硬件跳线

/home/dengxm2024/linuxProgDir/userside_code/digitdisplay/Digit_Display.c

#include<stdio.h>
#include<linux/spi/spidev.h>
#include<dirent.h>
#include<fcntl.h>
#include<string.h>
#include<sys/ioctl.h>


#define GPIO_RCK_PATH	"/sys/class/gpio/gpio117"

int spi_fd;
int RCK_fd;


int SPI1_Init( void )
{
	unsigned long mode = 0;
	unsigned long speed = 10000;
	unsigned long bits = 8;

	int fd;
	DIR *dir;

	dir = opendir( GPIO_RCK_PATH );
	if( dir == NULL )
	{
		fd = open( "/sys/class/gpio/export", O_WRONLY );
		if( fd ) 	
		{
			if( write( fd, "117", strlen( "117") ) == -1 )
			{
				close( fd );
				printf( "GPIO 3.21 export fail" );
				return -1;
			}
		}
		close( fd );
	} 	
	closedir( dir );

	fd = open( GPIO_RCK_PATH"/direction", O_WRONLY );
	write( fd, "out", strlen( "out" ) );
	close( fd );
	
	RCK_fd = open( GPIO_RCK_PATH"/value", O_RDWR ); 




	spi_fd = open( "/dev/spidev1.0", O_RDWR );
	if( spi_fd < 0 )
	{
		printf( "can not open spi device\n" );
		return -1;
	}

	if( ioctl( spi_fd, SPI_IOC_WR_MODE, &mode ) == -1 )
	{
		printf( "can not set SPI mode\n" );
		return -1;
	}

	if( ioctl( spi_fd, SPI_IOC_WR_BITS_PER_WORD, &bits ) )
	{
		printf( "can not set bits per word\n" );
	}
	if( ioctl( spi_fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed ) == -1 )
	{
		printf( "can not set max speed HZ\n" );
		return -1;
	}

	return 0;

}


unsigned char led_table[] = 
	{ 0x89, 0x86, 0xc7, 0xc7, 0x40, 0xFF, 0xFF, 0x86, 0xc7, 0x86, 0xc6, 0x8E, 0x88, 0xc8, 0x92, 0xFF, 0xFF, 0xFF };
int main( void )
{
	unsigned char LedValueIndex = 0;
	unsigned char LedDig = 0; 
	unsigned int Times = 0;
	unsigned char tx_buffer[2];

	struct spi_ioc_transfer tx[] =
	{
		{
			.tx_buf = ( unsigned long ) tx_buffer,
			.rx_buf = 0,
			.len = 2,
			.delay_usecs = 0,
			.speed_hz = 10000,
			.bits_per_word = 8,
		},
	};

	if( SPI1_Init() == -1 )
	{
		return 0;
	}

	while( 1 )
	{

		tx_buffer[0] = led_table[LedValueIndex + LedDig];
		tx_buffer[1] = 1 << LedDig; 
		ioctl( spi_fd, SPI_IOC_MESSAGE(1), & tx ); 

		write( RCK_fd, "0", 1 );
		usleep( 100 );
		write( RCK_fd, "1", 1 );

		usleep( 1000 );

		if( ++LedDig > 3 )
			LedDig = 0;

		if( ++Times > 500 )
		{
			Times = 0;
			if( ++LedValueIndex > 14 )
				LedValueIndex = 0;
		}
		

	}

	return 0;

}

/home/dengxm2024/linuxProgDir/userside_code/digitdisplay/Makefile

#CROSS_COMPILE是环境变量,是交叉编译工具的前缀,隐式声明编译器
CC = $(CROSS_COMPILE)gcc
CXX = $(CROSS_COMPILE)g++

#显示声明编译器
#CC = arm-fsl-linux-gnueabi-gcc
#CXX = arm-fsl-linux-gnueabi-g++
CFLAGS = -Wall -g
CXXFLAGS = -Wall -g

# 编译 main 可执行程序
Digit_Display: Digit_Display.o 
	$(CC) $(CFLAGS) Digit_Display.o  -o Digit_Display
Digit_Display.o: Digit_Display.c
	$(CC) $(CFLAGS) -c Digit_Display.c -o Digit_Display.o

# 伪目标, 删除所有目标文件
clean:
	rm *.o Digit_Display

编译:

dengxm2024@PC-202105142413:~/linuxProgDir/userside_code/digitdisplay$ make
arm-fsl-linux-gnueabi-gcc -Wall -g -c Digit_Display.c -o Digit_Display.o
Digit_Display.c: In function 'SPI1_Init':
Digit_Display.c:30: warning: implicit declaration of function 'write'
Digit_Display.c:32: warning: implicit declaration of function 'close'
Digit_Display.c: In function 'main':
Digit_Display.c:112: warning: implicit declaration of function 'usleep'
arm-fsl-linux-gnueabi-gcc -Wall -g Digit_Display.o  -o Digit_Display

传送编译结果到web服务器(Windows上做的web服务器,参看前面文章helloworld)

dengxm2024@PC-202105142413:~/linuxProgDir/userside_code/digitdisplay$ cp Digit_Display /mnt/d/imx280a_exe_folder/

开发板下载编译结果:

root@EasyARM-iMX28x ~# wget http://192.168.0.233:443/imx280a_exe_folder/Digit_Di
splay
Connecting to 192.168.0.233:443 (192.168.0.233:443)
Digit_Display        100% |*******************************| 10852   0:00:00 ETA
root@EasyARM-iMX28x ~# ls
Digit_Display      g_file_storage.ko  i2c_ds2460_test    start_qt
bcmdhd.ko          gpio_driver.ko     lradc.ko           up_wifi_module
beep.ko            hello              qt_hellow          usb_storage_up
beep_test          helloworld         qt_hellow_zh

修改编译结果,添加可执行属性(文件经过了windows系统传输,可执行的属性丢失了)

root@EasyARM-iMX28x ~# chmod +x Digit_Display 

执行编译结果:

root@EasyARM-iMX28x ~# ./Digit_Display 

查看开发板,4位led数码管显示屏已经显示了。

  • 20
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值