📄 spitest.c
字号:
#define IN_TGPIO#include "config.h"#define CS 25/* zi mo */uint8 const ShowTable[11] = { 0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0x80, 0x90, 0xFF};// 0 1 2 3 4 5 6 7 8 9 all off int main(){ int spi, gpio; uint8 c; int i; spi = open("/dev/SPI1", O_RDWR); if(spi == -1) { printf("\nCan't open SPI1!\n"); return -1; } gpio = open("/dev/P0", O_RDONLY); if(gpio == -1) { printf("\nCan't open P0!\n"); close(spi); return -1; } printf("Testing SPI1!\n"); ioctl(gpio, GPIO_SET_PIN_OUT, CS); // 74HC595 chip select ioctl(spi, SPI_SET_CLKDIV, 0x30); // Clock Diver ioctl(spi, SPI_SET_CPHA_FIRST); // CHAP ioctl(spi, SPI_SET_CPOL_LOW); // CPOL ioctl(spi, SPI_SET_LSBF_BIT7); // Bit7 First for (i = 0; i < 10; i++) { ioctl(spi, SPI_START); // Start SPI ioctl(gpio, GPIO_CLR_PIN, CS); // Chip Select c = ShowTable[i]; // get number write(spi, &c, 1); // Send data ioctl(gpio, GPIO_SET_PIN, CS); // Chip cs ioctl(spi, SPI_END); // end SPI printf("show %d\n",i); sleep(1); } printf("exit\n"); close(gpio); close(spi); return 0;}/*********************************************************************************************************** End Of File********************************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -