7 segment display and hc595
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-02-27 8:36 AM
Do not use scanning method.
Display with hc595 output.
display doing blink
The display does not remain steady when operating.
I suspect Spi.
I need help
thanks
#include "stm32f4xx_conf.h"
#include "stm32f4xx.h"
#include <stdio.h>
#define CLK GPIO_Pin_5
#define DATA GPIO_Pin_6
#define ENABLE GPIO_Pin_7
void spi_init(void);
void segment7(long counts);
unsigned char segment[10] = {0xFC,0x60,0xDA,0xF2,0x66,0xB6,0xBE,0xE0,0xFE,0xE6};
void spi_init(void){
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOG,ENABLE);
GPIO_InitStructure.GPIO_Pin = CLK | DATA|ENABLE;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOG, &GPIO_InitStructure);
GPIO_SetBits( GPIOC, CLK | DATA|ENABLE);
}
//hc595
void segment7(long counts) {
//////////DIJIT_1///////////////////////////////////////
for (i=0 ; i<8 ; i++){
GPIO_WriteBit(GPIOC, ENABLE, Bit_RESET);
GPIO_WriteBit(GPIOC, CLK, Bit_RESET);
GPIO_WriteBit(GPIOC,(segment[(counts/1)%10]>>i),&0x01);
delay_ms(20);
GPIO_WriteBit(GPIOC, CLK, Bit_SET);
delay_ms(20);
GPIO_WriteBit(GPIOC, CLK, Bit_RESET);
delay_ms(20);
}
GPIO_WriteBit(GPIOC, ENABLE, Bit_SET);
delay_ms(20);
//////////DIJIT_2///////////////////////////////////////
for (i=0 ; i<8 ; i++){
GPIO_WriteBit(GPIOC, ENABLE, Bit_RESET);
GPIO_WriteBit(GPIOC, CLK, Bit_RESET);
GPIO_WriteBit(GPIOC,(segment[(counts/10)%10]>>i),&0x01);
delay_ms(20);
GPIO_WriteBit(GPIOC, CLK, Bit_SET);
delay_ms(20);
GPIO_WriteBit(GPIOC, CLK, Bit_RESET);
delay_ms(20);
}
GPIO_WriteBit(GPIOC, ENABLE, Bit_SET);
delay_ms(20);
//////////DIJIT_3///////////////////////////////////////
for (i=0 ; i<8 ; i++){
GPIO_WriteBit(GPIOC, ENABLE, Bit_RESET);
GPIO_WriteBit(GPIOC, CLK, Bit_RESET);
GPIO_WriteBit(GPIOC,(segment[(counts/100)%10]>>i),&0x01);
delay_ms(20);
GPIO_WriteBit(GPIOC, CLK, Bit_SET);
delay_ms(20);
GPIO_WriteBit(GPIOC, CLK, Bit_RESET);
delay_ms(20);
}
GPIO_WriteBit(GPIOC, ENABLE, Bit_SET);
delay_ms(20);
//////////DIJIT_4///////////////////////////////////////
for (i=0 ; i<8 ; i++){
GPIO_WriteBit(GPIOC, ENABLE, Bit_RESET);
GPIO_WriteBit(GPIOC, CLK, Bit_RESET);
GPIO_WriteBit(GPIOC,(segment[(counts/1000)%10]>>i),&0x01);
delay_ms(20);
GPIO_WriteBit(GPIOC, CLK, Bit_SET);
delay_ms(20);
GPIO_WriteBit(GPIOC, CLK, Bit_RESET);
delay_ms(20);
}
GPIO_WriteBit(GPIOC, ENABLE, Bit_SET);
delay_ms(20);
//////////DIJIT_5///////////////////////////////////////
for (i=0 ; i<8 ; i++){
GPIO_WriteBit(GPIOC, ENABLE, Bit_RESET);
GPIO_WriteBit(GPIOC, CLK, Bit_RESET);
GPIO_WriteBit(GPIOC,(segment[(counts/10000)%10]>>i),&0x01);
delay_ms(20);
GPIO_WriteBit(GPIOC, CLK, Bit_SET);
delay_ms(20);
GPIO_WriteBit(GPIOC, CLK, Bit_RESET);
delay_ms(20);
}
GPIO_WriteBit(GPIOC, ENABLE, Bit_SET);
delay_ms(20);
//////////DIJIT_6///////////////////////////////////////
for (i=0 ; i<8 ; i++){
GPIO_WriteBit(GPIOC, ENABLE, Bit_RESET);
GPIO_WriteBit(GPIOC, CLK, Bit_RESET);
GPIO_WriteBit(GPIOC,(segment[(counts/100000)%10]>>i),&0x01);
delay_ms(20);
GPIO_WriteBit(GPIOC, CLK, Bit_SET);
delay_ms(20);
GPIO_WriteBit(GPIOC, CLK, Bit_RESET);
delay_ms(20);
}
GPIO_WriteBit(GPIOC, ENABLE, Bit_SET);
delay_ms(20);
}
////////////////////////////////////////////////////////////
int main(void) {
int data= 123456;
SystemInit();
spi_init();
while(1) {
delay_ms(100);
segment7(data);
}
}
- Labels:
-
STM32F4 Series
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-02-27 11:23 AM
Perhaps you can add some more white space or remove some subroutines?
My guess is it relates to configuring GPIOG clocks and pins, and then using GPIOC
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-02-27 12:01 PM
#include "stm32f4xx_conf.h"
#include "stm32f4xx.h"
#include <stdio.h>
#define CLK GPIO_Pin_5 // PC5 ?
#define DATA GPIO_Pin_6
#define ENABLE GPIO_Pin_7
void spi_init(void);
void segment7(long counts);
unsigned char segment[10] = {0xFC,0x60,0xDA,0xF2,0x66,0xB6,0xBE,0xE0,0xFE,0xE6};
void spi_init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOC, ENABLE);
GPIO_InitStructure.GPIO_Pin = CLK | DATA|ENABLE;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_SetBits(GPIOC, CLK | DATA|ENABLE);
}
//hc595
void digit(long a)
{
unsigned char b = segment[a];
int i;
for (i=0 ; i<8 ; i++)
{
GPIO_WriteBit(GPIOC, ENABLE, Bit_RESET);
GPIO_WriteBit(GPIOC, CLK, Bit_RESET);
GPIO_WriteBit(GPIOC, DATA, ((b >>i) & 0x01) ? Bit_SET : Bit_RESET);
delay_ms(20);
GPIO_WriteBit(GPIOC, CLK, Bit_SET);
delay_ms(20);
GPIO_WriteBit(GPIOC, CLK, Bit_RESET);
delay_ms(20);
}
GPIO_WriteBit(GPIOC, ENABLE, Bit_SET);
delay_ms(20);
}
void segment7(long counts)
{
//////////DIJIT_1///////////////////////////////////////
digit((counts/1) % 10);
//////////DIJIT_2///////////////////////////////////////
digit((counts/10) % 10);
//////////DIJIT_3///////////////////////////////////////
digit((counts/100) % 10);
//////////DIJIT_4///////////////////////////////////////
digit((counts/1000) % 10);
//////////DIJIT_5///////////////////////////////////////
digit((counts/10000) % 10);
//////////DIJIT_6///////////////////////////////////////
digit((counts/100000) % 10);
}
////////////////////////////////////////////////////////////
int main(void)
{
int data= 123456;
SystemInit();
spi_init();
while(1)
{
delay_ms(100);
segment7(data);
}
}
The DATA output looked busted too.
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-02-28 3:20 AM
You don't include the circuit. My guess would be you are clocking from the buffer shift reg to the output shift reg every clock rather than every 8 clocks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-02-28 4:41 AM
Thank you so much.
in main.
now work.
value showing full.
while (1) {
// winking here.
delay_ms (100);
segment7 (data);
}
I did something like that.
compiler gives warning but compiles.
src \ main.c | 1226 | warning: suggest parentheses around '-' inside '>>' [-Wparentheses] |
it works properly.
but (if) a lot.
void segment7(long counts){
int i=0;
for (i=0 ; i<48 ; i++){
GPIO_WriteBit(GPIOC, ENABLE, Bit_RESET);
GPIO_WriteBit(GPIOC, CLK, Bit_RESET);
if(i<8){
GPIO_WriteBit(GPIOC, DATA,(segment[(counts/1)%10]>>i)&0x01);
}
else if(i>8&&i<16)
{
GPIO_WriteBit(GPIOC, DATA,(segment[(counts/1)%10]>>i-8)&0x01);
}
else if(i>16&&i<24)
{
GPIO_WriteBit(GPIOC, DATA,(segment[(counts/1)%10]>>i-16)&0x01);
}
else if(i>24&&i<32)
{
GPIO_WriteBit(GPIOC, DATA,(segment[(counts/1)%10]>>i-24)&0x01);
}
else if(i>32&&i<40)
{
GPIO_WriteBit(GPIOC, DATA,(segment[(counts/1)%10]>>i-32)&0x01);
}
else if(i>40&&i<48)
{
GPIO_WriteBit(GPIOC, DATA,(segment[(counts/1)%10]>>i-40)&0x01);
}
delay_ms(20);
GPIO_WriteBit(GPIOC, CLK, Bit_SET);
delay_ms(20);
GPIO_WriteBit(GPIOC, CLK, Bit_RESET);
delay_ms(20);
}
GPIO_WriteBit(GPIOC, ENABLE, Bit_SET);
delay_ms(20);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-02-28 4:50 AM
I sent this value incorrectly.
That's the employee.
void segment7(long counts){
int i=0;
for (i=0 ; i<48 ; i++){
GPIO_WriteBit(GPIOC, ENABLE, Bit_RESET);
GPIO_WriteBit(GPIOC, CLK, Bit_RESET);
if(i<8){
GPIO_WriteBit(GPIOC, DATA,(segment[(counts/1)%10]>>i)&0x01);
}
else if(i>8&&i<16)
{
GPIO_WriteBit(GPIOC, DATA,(segment[(counts/10)%10]>>i-8)&0x01);
}
else if(i>16&&i<24)
{
GPIO_WriteBit(GPIOC, DATA,(segment[(counts/100)%10]>>i-16)&0x01);
}
else if(i>24&&i<32)
{
GPIO_WriteBit(GPIOC, DATA,(segment[(counts/1000)%10]>>i-24)&0x01);
}
else if(i>32&&i<40)
{
GPIO_WriteBit(GPIOC, DATA,(segment[(counts/10000)%10]>>i-32)&0x01);
}
else if(i>40&&i<48)
{
GPIO_WriteBit(GPIOC, DATA,(segment[(counts/100000)%10]>>i-40)&0x01);
}
delay_ms(20);
GPIO_WriteBit(GPIOC, CLK, Bit_SET);
delay_ms(20);
GPIO_WriteBit(GPIOC, CLK, Bit_RESET);
delay_ms(20);
}
GPIO_WriteBit(GPIOC, ENABLE, Bit_SET);
delay_ms(20);
}
