Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // blink.c
- //
- // Example program for bcm2835 library
- // Blinks a pin on an off every 0.5 secs
- //
- // After installing bcm2835, you can build this
- // with something like:
- // make or gcc -o led led.c -lbcm2835
- // sudo ./led
- /*
- define from bcm2835.h define from Board DVK511
- 3.3V | | 5V -> 3.3V | | 5V
- RPI_V2_GPIO_P1_03 | | 5V -> SDA | | 5V
- RPI_V2_GPIO_P1_05 | | GND -> SCL | | GND
- RPI_GPIO_P1_07 | | RPI_GPIO_P1_08 -> IO7 | | TX
- GND | | RPI_GPIO_P1_10 -> GND | | RX
- RPI_GPIO_P1_11 | | RPI_GPIO_P1_12 -> IO0 | | IO1
- RPI_V2_GPIO_P1_13 | | GND -> IO2 | | GND
- RPI_GPIO_P1_15 | | RPI_GPIO_P1_16 -> IO3 | | IO4
- VCC | | RPI_GPIO_P1_18 -> VCC | | IO5
- RPI_GPIO_P1_19 | | GND -> MOSI | | GND
- RPI_GPIO_P1_21 | | RPI_GPIO_P1_22 -> MISO | | IO6
- RPI_GPIO_P1_23 | | RPI_GPIO_P1_24 -> SCK | | CE0
- GND | | RPI_GPIO_P1_26 -> GND | | CE1
- ::if your raspberry Pi is version 1 or rev 1 or rev A
- RPI_V2_GPIO_P1_03->RPI_GPIO_P1_03
- RPI_V2_GPIO_P1_05->RPI_GPIO_P1_05
- RPI_V2_GPIO_P1_13->RPI_GPIO_P1_13:
- */
- #include <bcm2835.h>
- #include <stdio.h>
- typedef unsigned char uchar;
- typedef unsigned int uint;
- #define Max7219_pinCS RPI_GPIO_P1_24
- uchar disp1[38][8] = {
- // 0 to 9, A to Z, and special characters
- };
- void Delay_xms(uint x) {
- bcm2835_delay(x);
- }
- void Write_Max7219_byte(uchar DATA) {
- uchar i;
- bcm2835_gpio_write(Max7219_pinCS, LOW);
- bcm2835_spi_transfer(DATA);
- }
- void Write_Max7219(uchar address1, uchar dat1, uchar address2, uchar dat2) {
- bcm2835_gpio_write(Max7219_pinCS, LOW);
- Write_Max7219_byte(address1);
- Write_Max7219_byte(dat1);
- Write_Max7219_byte(address2);
- Write_Max7219_byte(dat2);
- bcm2835_gpio_write(Max7219_pinCS, HIGH);
- }
- void Init_MAX7219(void) {
- Write_Max7219(0x09, 0x00, 0x09, 0x00);
- Write_Max7219(0x0a, 0x03, 0x0a, 0x03);
- Write_Max7219(0x0b, 0x07, 0x0b, 0x07);
- Write_Max7219(0x0c, 0x01, 0x0c, 0x01);
- Write_Max7219(0x0f, 0x00, 0x0f, 0x00);
- }
- int main(void) {
- uchar i, j;
- if (!bcm2835_init()) return 1;
- bcm2835_spi_begin();
- bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST);
- bcm2835_spi_setDataMode(BCM2835_SPI_MODE0);
- bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_256);
- bcm2835_gpio_fsel(Max7219_pinCS, BCM2835_GPIO_FSEL_OUTP);
- Delay_xms(50);
- Init_MAX7219();
- while(1) {
- for(j = 0; j < 37; j++) {
- for(i = 1; i < 9; i++) {
- Write_Max7219(i, disp1[j+1][i-1], i, disp1[j][i-1]);
- }
- Delay_xms(1000);
- }
- }
- bcm2835_spi_end();
- bcm2835_close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement