Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] PIC 16F84A Dual display counter

Status
Not open for further replies.

nav28ge

Newbie level 2
Joined
May 16, 2014
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
42
Hi Every one,

can any one help me, my 7 segment dual display counter is counting from 0-99 how to make it start from 0 once it reaches 99 I am using PIC 16F84A

my code is


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
void main()
{
 int loop = 0;                  /* Initialising loop variable to zero */
 
 PORTA = 0;                     /* Initialising PORTA and PORTB as OUTPUT PORTS*/
 trisa = 0b00000;
 PORTB = 0;
 trisb = 0b00000000;
 asm BCF PORTA,3
 PORTB= 0b11111111;             /* Blanking the LED2  */
 asm BSF PORTA,3
 asm BCF PORTA,3
 asm BCF PORTA,4
 PORTB= 0b11111111;              /* Blanking the LED1  */
 asm BSF PORTA,4
 asm BCF PORTA,4;
 
 while(1)
 {
  PORTB= 0b11111111;           /*Making portB bits as high */
  PORTA = 0b00000;             /*Making portA bits as LOW */
  asm BCF PORTA,3
  PORTB=0b00000011;            /*Sending  the data '0' to LED2 and enabling the clock to display it */
  asm BSF PORTA,3
    Delay_ms(500);
  asm BCF PORTA,3
   PORTB=0b10011111;             /*Sending the data '1' to LED2 and enabling the clock to display it */
  asm BSF PORTA,3
  Delay_ms(500);
  asm BCF PORTA,3
  Delay_ms(500);
 
  PORTB=0b00100101;             /*Sending the data '2' to LED2 and enabling the clock to display it */
  asm BSF PORTA,3
  Delay_ms(500);
  asm BCF PORTA,3
  Delay_ms(500);
  PORTB=0b00001101;             /*Sending the data '3' to LED2 and enabling the clock to display it */
  asm BSF PORTA,3
  Delay_ms(500);
  asm BCF PORTA,3
  Delay_ms(500);
  PORTB= 0b10011001;            /*Sending the data '4' to LED2 and enabling the clock to display it */
  asm BSF PORTA,3
  Delay_ms(500);
  asm BCF PORTA,3
  Delay_ms(500);
  PORTB = 0b01001001;           /*Sending the data '5' to LED2 and enabling the clock to display it */
  asm BSF PORTA,3
  Delay_ms(500);
  asm BCF PORTA,3
  Delay_ms(500);
  PORTB = 0b11000001;          /*Sending the data '6' to LED2 and enabling the clock to display it */
  asm BSF PORTA,3
  Delay_ms(500);
  asm BCF PORTA,3
  Delay_ms(500);
  PORTB = 0b00011111;          /*Sending the data '7' to LED2 and enabling the clock to display it */
  asm BSF PORTA,3
  Delay_ms(500);
  asm BCF PORTA,3
  Delay_ms(500);
  PORTB = 0b00000001;          /*Sending the data '8' to LED2 and enabling the clock to display it */
  asm BSF PORTA,3
  Delay_ms(500);
  asm BCF PORTA,3
  Delay_ms(500);
  PORTB = 0b00011001;          /*Sending the data '9' to LED2 and enabling the clock to display it */
  asm BSF PORTA,3
  Delay_ms(500);
  asm BCF PORTA,3
  Delay_ms(500);
 
  loop = loop + 1 ;       /*incrementing the loop variable */
 
  if(loop == 1)          /* checking the loop condition   */
  {
   asm BCF PORTA,4
   Delay_ms(500);
   PORTB=0b10011111;     /*Sending the data '1' to LED1 and enabling the clock to display it */
   asm BSF PORTA,4
   asm BCF PORTA,4;
  }
 
  if(loop == 2)
  {
   asm BCF PORTA,4
   Delay_ms(500);
   PORTB=0b00100101;      /*Sending the data '2' to LED1 and enabling the clock to display it */
   asm BSF PORTA,4
   asm BCF PORTA,4;
   }
 
   if(loop == 3)
   {
   asm BCF PORTA,4
   Delay_ms(500);
   PORTB=0b00001101;    /*Sending the data '3' to LED1 and enabling the clock to display it */
   asm BSF PORTA,4
   asm BCF PORTA,4;
   }
 
   if(loop == 4)
   {
   asm BCF PORTA,4
   Delay_ms(500);
   PORTB=0b10011001;    /*Sending the data '4' to LED1 and enabling the clock to display it */
   asm BSF PORTA,4
   asm BCF PORTA,4;
   }
 
  if(loop == 5)
  {
   asm BCF PORTA,4
   Delay_ms(500);
   PORTB=0b01001001;   /*Sending the data 5' to LED1 and enabling the clock to display it */
   asm BSF PORTA,4
   asm BCF PORTA,4;
  }
 
 
  if(loop == 6)
  {
   asm BCF PORTA,4
   Delay_ms(500);
   PORTB=0b11000001;    /*Sending the data '6' to LED1 and enabling the clock to display it */
   asm BSF PORTA,4
   asm BCF PORTA,4;
  }
 
 
  if(loop == 7)
  {
   asm BCF PORTA,4
   Delay_ms(500);
   PORTB=0b00011111;    /*Sending the data '7' to LED1 and enabling the clock to display it */
   asm BSF PORTA,4
   asm BCF PORTA,4;
  }
 
 
  if(loop == 8)
  {
   asm BCF PORTA,4
   Delay_ms(500);
   PORTB=0b00000001;    /*Sending the data '8' to LED1 and enabling the clock to display it */
   asm BSF PORTA,4
   asm BCF PORTA,4;
  }
 
 
  if(loop == 9)
  {
   asm BCF PORTA,4
   Delay_ms(500);
   PORTB=0b00011001;    /*Sending the data '9' to LED1 and enabling the clock to display it */
   asm BSF PORTA,4
   asm BCF PORTA,4;
  }
 
 
   }
 }

 
Last edited by a moderator:

1. What does the clock signal do? You have given no indication of the hardware you are using.
2. Did you intend to write this in 'C' or in assembly language, it is a curious mix of the two.

Brian.
 

1. What does the clock signal do? You have given no indication of the hardware you are using.
2. Did you intend to write this in 'C' or in assembly language, it is a curious mix of the two.

Brian.

Hi brian,

Thank you for reply, my programme is in micro c, regarding my circuit is a 7segment counter. it counts from 0 to 99 I have used pic16F84A and a flip flop connected to it, everything working it is counting from 0-99. It is not reseting after it counts 99. Give me some idea how to reset it back yo start grom 0 again.
 

It is VERY far from well written but I think what you are needing is an extra step at the end of all your loops saying:

Code:
if(loop == 10) loop = 0;

Take my advice and get rid of all those 'asm' statements and replace them with instructions in 'C' instead. Also use names for the bits instead of their values and consider a switch(loop) construct instead of lots of 'if' lines. You can make the program much smaller and far more readble if you do these simple things.

Brian.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top