Microcontroller › 8051 › Problem with 7 segment common Cathode display using C8051F350 Micro Controller
- This topic has 1 reply, 2 voices, and was last updated 13 years ago by
AJISH ALFRED.
Viewing 2 posts - 1 through 2 (of 2 total)
-
AuthorPosts
-
February 22, 2013 at 8:55 am #3850
Nallapaneni Sai Sankar
Participant//
#include <c8051f350.h>#include<stdio.h> // SFR declarationssbit strobe =P1^1;sbit din =P1^0;sbit clk =P0^7;/*all chipselects are configured here using sbit;all on P1*/sbit cs1 =P1^7;sbit cy =PSW^7; //ealrier declared as globalbit temp;unsigned char dd[10] ={~0x3f,~0x06,~0x5b,~0x4f,~0x66,~0x6d,~0x7d,~0x07,~0x7f,~0x6f};unsigned int value;void delay(void) //creating trouble{TMOD=0x10;TL1=0xfb;TH1=0xff;TR1=1;while(TF1==0);TF1=0;TR1=0;}void senddata(unsigned char x){unsigned char i;din = 0;cy = 0;strobe = 1;temp =0;P2 = x;for(i=1; i<=8; i++){cy=0;x= x << 1; //shifting x places the MSB in carryflag(cy);temp = cy;din=temp; //data input to the shift register should be sended serially;clk=1;clk=0;}strobe=1;strobe=0;}void display(char f1){cs1 = 0x01; //before every data send operation data line should be cleared sending 0xffif(value == 10){senddata(f1);cs1 &=0x00;delay();cs1 |=0x01;}else{senddata(0xff);cs1 &=0x00;delay();cs1 |=0x01;if(value == 20)value = 0;}}//
// MAIN Routine//
void led_display(){while(1){value++;display(dd[~0x3f]);}}Thye above is the code that i am using to blink a value in a 7 segment display but what happening is after "2 increments of the 'value' it was getting resetted and the 'value' is becoming zero" and when i doing on board debugging after 'value' becomes 2 it was automaticalli becoming zero and going into start up code . Help me anyone to solve this .February 22, 2013 at 10:40 am #9166AJISH ALFRED
ParticipantHi Nallapaneni,
It is obvious that your delay () function is causing trouble. For this particular project precise delay don’t have that much significance.
Just create a delay using loop waiting technique.
For example;
void delay_us ( int us )
{
volatile int uss;
uss = us;
for ( ; uss; uss — ); //assume 1 microsecond for each loop
}
-
AuthorPosts
Viewing 2 posts - 1 through 2 (of 2 total)
- You must be logged in to reply to this topic.