int i_rad_display(const char* input) { int status = -1; if ((status = check_setup()) != 0) { return status; } signed char i = 0; // char position unsigned char j; // register counter i = strlen(input) - 1; j = 0; for(; i >= 0; i--) { printf("%c ", (char) input[i]); switch(input[i]) { case '-': REGISTER[j++] |= 0xa; break; case 'e': case 'E': REGISTER[j++] |= 0xb; break; case 'h': case 'H': REGISTER[j++] |= 0xc; break; case 'l': case 'L': REGISTER[j++] |= 0xd; break; case 'p': case 'P': REGISTER[j++] |= 0xe; break; case ' ': REGISTER[j++] |= 0xf; break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': REGISTER[j++] |= (input[i] - 48); break; case '.': REGISTER[j] = 0x80; break; // set dot default: printf("Error value '%s'!\n", input[i]); exit(1); break; } if( j > DIGITS + 1 ) { printf("Input longer then expected!\n"); exit(1); } } Init7219( DIGITS, MODE_B, 8 ); for(i = 0; i<8; i++) { printf("REGISTER[%d] = '%#x'\n", i, REGISTER[i]); MAX7219Send(i+1, REGISTER[i]); } return 0; }
// Initialise 7219 // // To try and ensure device initialised correctly always // // Leaves device in Test mode // // Pass in // digits - number of digits to display - 1 (1 digit pass in 0) // mode - display mode 7 segment (MODE_7SEG) control // Segment Data bit 0 = seg A to bit 6 = seg G and bit 7 = DP // or decode special set (MODE_B) as below // Segment Data bits 0 to 3: 0 to 15 = 0 to 9, -, E, H, L, P, and ' ' (blank) // note top 4 bits ignored // level - intensity level (1-15) // // Exits program if no wiringPi installed or invalid parameters or LOAD fails to go high // void Init7219( int digits, int mode, int level ) { // Initial checks if( wiringPiSetup () == -1 ) exit( 1 ); if( digits < 0 || digits > 7 ) { printf( "\nError Init7219 called with invalid number of digits of %d (should be 0 to 7)\n", digits ); exit( 1 ); } //if( mode != MODE_B || mode != MODE_7SEG || level < 0 || level > 15 ) if( level < 0 || level > 15 ) { printf( "\nError Init7219 invalid brigthness of %d!\n", level); exit( 1 ); } //We need 3 output pins to control the Max7219: Data, Clock and Load pinMode( DATA, OUTPUT ); pinMode( CLOCK, OUTPUT ); pinMode( LOAD, OUTPUT ); // Initial states of pins digitalWrite( LOAD, 1 ); // set LOAD 1 to start digitalWrite( CLOCK, 0 ); // set CLOCK to 0 digitalWrite( DATA, 0 ); // set DATA to 0 // Quick test check LOAD pin actually HIGH as test if( digitalRead( LOAD ) != 1 ) { printf( "\nError Max7219 LOAD pin %u failed to go high\n", LOAD ); exit( 2 ); } // Ensure shift refister is all zeros no random clocks occured // and loaded into device to synchronise shift register MAX7219Send( NO_OP, 0 ); MAX7219Send( SCAN_LIMIT, digits ); // set up to scan number of digits MAX7219Send( DECODE_MODE, mode ); // Set BCD decode mode MAX7219Send( DISPLAY_TEST, 0); // disable test mode MAX7219Send( INTENSITY, level ); // set brightness 0 to 15 MAX7219Send( SHUTDOWN, 1 ); // Ensure in Normal mode of operation }
int main (void) { int i, j; int sleep = 15; printf ("MrRetupmoc's Raspberry Pi - Bi-Polar Stepper\n"); if (wiringPiSetup () == -1) exit (1); // WiringPi Setup pinMode(DATA, OUTPUT); // Setup Output Mode for Data pinMode(CLOCK, OUTPUT); // Setup Output Mode for Clock pinMode(LOAD, OUTPUT); // Setup Output Mode for Load MAX7219Send(SCAN_LIMIT, 16); // Scan Limit // BCD decode mode off : data bits correspond to the segments (A-G and DP) of the seven segment display. // BCD mode on : 0 to 15 = 0 to 9, -, E, H, L, P, and ' ' MAX7219Send(DECODE_MODE, 0); // Set BCD decode mode on MAX7219Send(DISPLAY_TEST, 0); // Disable test mode MAX7219Send(INTENSITY, 15); // set brightness 0 to 15 MAX7219Send(SHUTDOWN, 1); // come out of shutdown mode / turn on the digits for (j = 1; j < 10; j++) // Loop For 9 Times or J, Forward First { printf ("Step Forward \n"); // Print "Stepping Forward" for(i = 0; i < (100 / j); i++) // Loop For 100 Divided by J { MAX7219Send(1,0); // Displays the binary number 00 delay(sleep); // Sleep MAX7219Send(1,2); // Displays the binary number 10 delay(sleep); // Sleep } delay(500); // Sleep printf ("Step Backward \n"); // Print "Stepping Backward" for(i = 0; i < (100 / j); i++) // Loop For 100 Divided by J { MAX7219Send(1,1); // Displays the binary number 01 delay(sleep); // Sleep MAX7219Send(1,3); // Displays the binary number 11 delay(sleep); // Sleep } } for (j = 1; j < 10; j++) // Loop For 9 Times or J, Backward First { printf ("Step Backward \n"); // Print "Stepping Backward" for(i = 0; i < (100 / j); i++) // Loop For 100 Divided by J { MAX7219Send(1,1); // Displays the binary number 01 delay(sleep); // Sleep MAX7219Send(1,3); // Displays the binary number 11 delay(sleep); // Sleep } delay(500); // Sleep printf ("Step Forward \n"); // Print "Stepping Forward" for(i = 0; i < (100 / j); i++) // Loop For 100 Divided by J { MAX7219Send(1,0); // Displays the binary number 00 delay(sleep); // Sleep MAX7219Send(1,2); // Displays the binary number 10 delay(sleep); // Sleep } } delay(500); // Sleep MAX7219Send(SHUTDOWN, 0); // Turn OFF the AS1100 Controller delay(200); // Sleep return 0; }