Pic Project

Discussion in 'The Projects Forum' started by royalmadhu, Feb 4, 2011.

  1. royalmadhu

    Thread Starter New Member

    Feb 4, 2011
    6
    0
    Hi i'm trying to build a circuit that tells the time in seconds in four 7 segment displays when a button is being pressed...I'm using a 16F84A... i have used latch enabled decoders .i have assigned the certain button to porta.f0


    the problem is when i run the program in Proteus and it only shows 0000..no matter how long i pressed it..when i put count=4546 like a number in the main function it shows that...but it doesnt shpw it when i put it outside the main function..
    this is my program

    plzzz help me

    thx in advance

    Code ( (Unknown Language)):
    1.  
    2.  
    3.  unsigned int count,count1;
    4.  
    5. void display(int,int,int,int)  ;
    6.  
    7. void interupt(void)
    8. {
    9.  
    10. if (intcon.t0if==1)
    11.  {
    12.  if (porta.f0==1)
    13.  {
    14.  
    15. count1=count1+1;
    16.  
    17. if (count1==10)
    18. {
    19. count1=0;
    20. count=count++;
    21. if (count ==9999)
    22. {
    23. count=0;
    24. }
    25. }
    26. }
    27. }
    28. else if(porta.f1==1)
    29. {
    30. count1=0;
    31. count=0;
    32. }
    33. intcon.t0if=0;
    34.  
    35.  
    36. }
    37.  
    38. void main()
    39. {
    40. int a,b,c,d;
    41. intcon= 0b10100000;
    42. option_reg= 0b00000111;
    43. trisa=0b11111;
    44. trisb=0b000000000;
    45. count1=count=0;
    46.  
    47. while(1)
    48. {
    49. a=count/1000;
    50. b=((count%1000)/100);
    51. c=(((count%1000)%100)/10);
    52. d=((((count%1000)%100)%10)/1);
    53. display(a,b,c,d);
    54. }
    55. }
    56.  
    57. void display(int x,int y,int z,int w)
    58. {
    59. if (x==0)
    60. {
    61. portb=0b00000001;
    62. }
    63. if (x==1)
    64. {
    65. portb=0b00010001;
    66. }
    67. if (x==2)
    68. {
    69. portb=0b00100001;
    70. }
    71. if (x==3)
    72. {
    73. portb=0b00110001;
    74. }
    75. if (x==4)
    76. {
    77. portb=0b01000001;
    78. }
    79. if (x==5)
    80. {
    81. portb=0b01010001;
    82. }
    83. if (x==6)
    84. {
    85. portb=0b01100001;
    86. }
    87. if (x==7)
    88. {
    89. portb=0b01110001;
    90. }
    91. if (x==8)
    92. {
    93. portb=0b10000001;
    94. }
    95. if (x==9)
    96. {
    97. portb=0b10010001;
    98. }
    99. if (y==0)
    100. {
    101. portb=0b00000010;
    102. }
    103. if (y==1)
    104. {
    105. portb=0b00010010;
    106. }
    107. if (y==2)
    108. {
    109. portb=0b00100010;
    110. }
    111. if (y==3)
    112. {
    113. portb=0b00110010;
    114. }
    115. if (y==4)
    116. {
    117. portb=0b01000010;
    118. }
    119. if (y==5)
    120. {
    121. portb=0b01010010;
    122. }
    123. if (y==6)
    124. {
    125. portb=0b01100010;
    126. }
    127. if (y==7)
    128. {
    129. portb=0b01110010;
    130. }
    131. if (y==8)
    132. {
    133. portb=0b10000010;
    134. }
    135. if (y==9)
    136. {
    137. portb=0b10010010;
    138. }
    139. if (z==0)
    140. {
    141. portb=0b00000100;
    142. }
    143. if (z==1)
    144. {
    145. portb=0b00010100;
    146. }
    147. if (z==2)
    148. {
    149. portb=0b00100100;
    150. }
    151. if (z==3)
    152. {
    153. portb=0b00110100;
    154. }
    155. if (z==4)
    156. {
    157. portb=0b01000100;
    158. }
    159. if (z==5)
    160. {
    161. portb=0b01010100;
    162. }
    163. if (z==6)
    164. {
    165. portb=0b01100100;
    166. }
    167. if (z==7)
    168. {
    169. portb=0b01110100;
    170. }
    171. if (z==8)
    172. {
    173. portb=0b10000100;
    174. }
    175. if (z==9)
    176. {
    177. portb=0b10010100;
    178. }
    179. if (w==0)
    180. {
    181. portb=0b00001000;
    182. }
    183. if (w==1)
    184. {
    185. portb=0b00011000;
    186. }
    187. if (w==2)
    188. {
    189. portb=0b00101000;
    190. }
    191. if (w==3)
    192. {
    193. portb=0b00111000;
    194. }
    195. if (w==4)
    196. {
    197. portb=0b01001000;
    198. }
    199. if (w==5)
    200. {
    201. portb=0b01011000;
    202. }
    203. if (w==6)
    204. {
    205. portb=0b01101000;
    206. }
    207. if (w==7)
    208. {
    209. portb=0b01111000;
    210. }
    211. if (w==8)
    212. {
    213. portb=0b10001000;
    214. }
    215. if (w==9)
    216. {
    217. portb=0b10011000;
    218. }
    219.  
    220. }
    221.  
    222.  
     
    Last edited by a moderator: Feb 4, 2011
  2. debjit625

    Well-Known Member

    Apr 17, 2010
    790
    186
    Check from datasheet if you have set properly the interupt reg or not like option reg , intcon reg in main function ,I dont think so you have did it properly .
    If yes then also your program will not function properly because your logic is not correct i.e..
    Not every time your interupt occurs,and you have gave a condition that the count variable be only updated if PORTA.F0 is 1 so it cant update its time if you dont press your switch.

    Code ( (Unknown Language)):
    1.  
    2. if (intcon.t0if==1)
    3. {
    4.   if (porta.f0==1)
    5.   {
    6.     //.....your code..........
    7.   }
    8. }
    9.  
    To check
    Put the codeof "if(porta.f0 == 1) {....}" from the interupt function inside the main's while() loop to check how it works.

    Good Luck
     
  3. debjit625

    Well-Known Member

    Apr 17, 2010
    790
    186
    One more thing when using language "C" we dont write that big algo as you did it for display function their are more better way to do that display stuff but for now its ok as it seems you are also new to "C".

    Anyway welcome to AAC.
     
  4. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,887
    1,012
    Did you make any attempt at all to debug your own code?

    First you need to determine the source of your problem. Is it input or your output that is causing the problem.

    Determine that your input code is working as expected or not. Write a small sample program just to test the input. Post ONLY that code. But first debug it on your own. After and only after you have done some debugging on your own, post back with your findings and I will try and help further.
     
Loading...