cancel
Showing results for 
Search instead for 
Did you mean: 

I want to display counter values from stm8s to 3 digit seven segment display via 74hc595, but was .unable to do so.Any suggestion will be appreciated .

Dshar.1
Associate II

In my project i have interfaced stm8s003f3 with3 digit 7 segment display via 74hc595d in order to reduce the used pin count in stm8s. From the Stm8s 3 pin are to 74hc595d (sh_cp,st_cp,ds) and three pin to digits pin of 7 segment display. I attaching my program code. please provide some suggestions .

 /* MAIN.C file

 * 

 * Copyright (c) 2002-2005 STMicroelectronics

 */

#include "stm8s.h"

void clock_setup(void);

void GPIO_SETUP(void);

void serial_clock(void);

void latch_enable(void);

void data_show(unsigned char data);

void digit_cal(unsigned char digit);

void _delay_us(int delay);

unsigned char Numbers[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};

main()

{

GPIO_SETUP();

clock_setup();

digit_cal(1);

while (TRUE)

{

//digit_cal(1);

}

}

void GPIO_SETUP(void)

{

GPIO_DeInit(GPIOD);

GPIO_Init(GPIOA,GPIO_PIN_3,GPIO_MODE_OUT_PP_HIGH_FAST);

GPIO_DeInit(GPIOC);

GPIO_Init(GPIOC,GPIO_PIN_3,GPIO_MODE_OUT_PP_LOW_FAST);

GPIO_Init(GPIOC,GPIO_PIN_4,GPIO_MODE_OUT_PP_LOW_FAST);

GPIO_Init(GPIOC,GPIO_PIN_5,GPIO_MODE_OUT_PP_HIGH_FAST);

GPIO_Init(GPIOC,GPIO_PIN_6,GPIO_MODE_OUT_PP_HIGH_FAST);

GPIO_Init(GPIOC,GPIO_PIN_7,GPIO_MODE_OUT_PP_HIGH_FAST);

}

void serial_clock(void)

{

GPIO_WriteHigh(GPIOA, GPIO_PIN_3);

_delay_us(10000);

GPIO_WriteLow(GPIOA, GPIO_PIN_3);

_delay_us(10000);

}

void latch_enable(void)

{

GPIO_WriteHigh(GPIOC,GPIO_PIN_4);

_delay_us(10000);

GPIO_WriteLow(GPIOC,GPIO_PIN_4);

_delay_us(10000);

}

void data_show(unsigned char data)

{

int i=0;

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

{

if((data>>i) & 0x01)

{

GPIO_WriteHigh(GPIOC,GPIO_PIN_3);

}

else

{

GPIO_WriteHigh(GPIOC,GPIO_PIN_3);

}

serial_clock();

}

latch_enable();

}

void digit_cal(unsigned char digit_in)

{

int seg=1;

int n=0;

switch(seg)

{

case 1:

{

n=((digit_in/100)%10);

data_show(Numbers[n]);

GPIO_WriteHigh(GPIOC,GPIO_PIN_5);

break;

}

case 2:

{

n=((digit_in/10)%10);

data_show(Numbers[n]);

GPIO_WriteHigh(GPIOC,GPIO_PIN_6);

break;

}

case 3:

{

n=(digit_in%10);

data_show(Numbers[n]);

GPIO_WriteHigh(GPIOC,GPIO_PIN_7);

break;

}

}

seg ++;

if (seg>1)

{

seg=1;

}

}

void _delay_us(int delay)

{

int m=0;

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

{

;

}

}

void clock_setup(void)

{

   CLK_DeInit();

         

   CLK_HSECmd(DISABLE);

   CLK_LSICmd(DISABLE);

   CLK_HSICmd(ENABLE);

   while(CLK_GetFlagStatus(CLK_FLAG_HSIRDY) == FALSE);

         

   CLK_ClockSwitchCmd(ENABLE);

   CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV8);

   CLK_SYSCLKConfig(CLK_PRESCALER_CPUDIV1);

         

   CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_HSI, 

   DISABLE, CLK_CURRENTCLOCKSTATE_ENABLE);

         

   CLK_PeripheralClockConfig(CLK_PERIPHERAL_SPI, DISABLE);

   CLK_PeripheralClockConfig(CLK_PERIPHERAL_I2C, DISABLE);

   CLK_PeripheralClockConfig(CLK_PERIPHERAL_ADC, DISABLE);

   CLK_PeripheralClockConfig(CLK_PERIPHERAL_AWU, DISABLE);

   CLK_PeripheralClockConfig(CLK_PERIPHERAL_UART1, DISABLE);

   CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER1, DISABLE);

   CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER2, DISABLE);

   CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER4, DISABLE);

}

0 REPLIES 0