0% found this document useful (0 votes)
59 views

Display C

This C code defines functions for initializing and controlling a TM1637 7-segment LED display module. The display_init function initializes the display module pins and sets the brightness level. The display_number function displays a 16-bit number on the 4-digit display by extracting the individual digits. The write_byte function transmits a byte of data to the display by toggling the clock and data pins.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views

Display C

This C code defines functions for initializing and controlling a TM1637 7-segment LED display module. The display_init function initializes the display module pins and sets the brightness level. The display_number function displays a 16-bit number on the 4-digit display by extracting the individual digits. The write_byte function transmits a byte of data to the display by toggling the clock and data pins.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

/*

* File: display.c
* Author: Jarrett Rainier
* Comments: TM1637 driver for the newer 8-bit PIC16F / PIC18F series
* Requires pins configured as OD (open drain) and WPU (weak pull up)
* Revision history:
*/

#include "display.h"

void display_init(uint8_t brightness) {


DO_SetDigitalOutput();
DO_SetOpenDrain();
CLK_SetDigitalOutput();
CLK_SetOpenDrain();
display_sof();
write_byte(0x88 | brightness);
display_eof();
}

void display_number(uint16_t number) {


uint8_t digit4 = digitToSegment[number & 0x0F];
uint8_t digit3 = digitToSegment[(number >> 4) & 0x0F];
uint8_t digit2 = digitToSegment[(number >> 8) & 0x0F];
uint8_t digit1 = digitToSegment[(number >> 12) & 0x0F];
display_values(digit1, digit2, digit3, digit4);

void write_byte(uint8_t digit) {


uint8_t i;
unsigned int delay;

for(i=0; i < 8; i++)


{
CLK_SetLow();
for(delay = 0; delay < DISPLAY_DELAY; delay++);

if(digit & 0x01)


DO_SetHigh();
else
DO_SetLow();

for(delay = 0; delay < DISPLAY_DELAY; delay++);

digit = digit >> 1;


CLK_SetHigh();

for(delay = 0; delay < DISPLAY_DELAY; delay++);


}
display_ack();
}

void display_values(uint8_t digit1, uint8_t digit2, uint8_t digit3, uint8_t digit4)


{

display_sof();
write_byte(0x40);
display_eof();

display_sof();

write_byte(0xC0);

write_byte(digit1);

write_byte(digit2);

write_byte(digit3);

write_byte(digit4);

display_eof();
}

void display_sof(void) {
unsigned int delay;

CLK_SetHigh();
DO_SetHigh();
for(delay = 0; delay < DISPLAY_DELAY; delay++);
DO_SetLow();
}

void display_ack(void) {
unsigned int delay;

CLK_SetLow();
DO_SetDigitalInput();

for(delay = 0; delay < DISPLAY_DELAY; delay++);

CLK_SetHigh();
while(DO_GetValue());

CLK_SetLow();
for(delay = 0; delay < DISPLAY_DELAY; delay++);
DO_SetDigitalOutput();
for(delay = 0; delay < DISPLAY_DELAY; delay++);
}

void display_eof(void) {
unsigned int delay;
CLK_SetLow();
for(delay = 0; delay < DISPLAY_DELAY; delay++);
DO_SetLow();
for(delay = 0; delay < DISPLAY_DELAY; delay++);
CLK_SetHigh();
for(delay = 0; delay < DISPLAY_DELAY; delay++);
DO_SetHigh();
}

You might also like