2 Document : $page = bones/default.html --- $idat= raspberry/gpiodemo/rpitest.c
$img=
Zdanetix
 
 

  
/****************************************************************** * rpitest.c - Raspberry Pi GPIO test et démo * * Copyright ©2015 Helmut Müller * * Edits: * 1 30-nov-15 creation * 2 06-dec-15 english version */ #define _CRT_SECURE_NO_WARNINGS #include #include #include "bcm2835.h" char *text0 = "\n\nRaspberry Pi GPIO demo and test program\n"; char *text1 = "\nInitialization error, status=%d 0x%x, sudo ?\n\n"; char *text2 = "\nBCM interface GPIO byte number [0..3] ? : "; char *text3 = "Mask of pins to clear/set [hex 00..FF] ? : "; int main(int argc, char **argv) { int status; unsigned int ans = 0; unsigned int data = 0; unsigned int bank = 0; // Initialisation printf(text0); status = bcm_setup(); if (status) { printf(text1, status, status); exit(0); } for (bank = 0; bank < 4; bank++) gpio_setout(bank, 0xff); bank = 0; // Grande boucle while (1) { printf(text2); if (!scanf("%d", &ans)) exit(0); bank = ans & 3; printf(text3); if (!scanf("%x", &ans)) exit(0); data = ans & 0xff; gpio_write(bank, data, 0xff); } // while (1) } /* * Windows debugging */ #ifdef _WIN32 // Stubs for functions in BCM2835.c int bcm_setup(void) { return 0; } void gpio_setout(unsigned char bank, unsigned char mask) {} /* * gpio_write() - GPIO Windows simulation * * This function displays a 4x8 matrix of dots (for bit=0) and x (for bit=1) * showing the simulated state of the GPIO pins after each command. */ void gpio_write(unsigned char bank, unsigned char data, unsigned char mask) { static unsigned char leds[4]; int m,n; leds[bank] = (data & mask) | (leds[bank] & ~mask); printf("\n\t7 6 5 4 3 2 1 0\n\t"); for (m = 0; m < 4; m++) { for (n = 7; n >= 0; n--) if (leds[m] & (1<