CNCzone.com-The Largest Machinist Community on the net!



Home Page Mark Forums Read Today's Posts My Replies Classifieds Reviews Photo Gallery Web Links Share Files Advertise With Us Ad List
Go Back   CNCzone.com-The Largest Machinist Community on the net! > Electronics > PIC Programing / Design


PIC Programing / Design Discuss programing of PIC chips here and design of electronics using PIC chips.


Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Ban this user!
Old 05-27-2009, 07:47 AM
 
Join Date: Mar 2009
Location: Slovenia
Posts: 4
Razer is on a distinguished road
16F84 7 segment display

Hi,
I need help on programing a 16F84 in assembler code to make it display hexadecimal values from 0 to F in a range of 0,5 sec with TMR0 on a 7 segment display. I will post some code later.
Reply With Quote

  #2   Ban this user!
Old 05-27-2009, 08:40 AM
 
Join Date: Aug 2008
Location: Australia
Posts: 3
gorders1 is on a distinguished road
pic Programming

Hi The info you need is in the books supplied at this website
https://www.sq-1.com/
I have purchased all but a couple of these books and they are brilliant. Wanna be to for the cost to get them to Australia lol. Seriously check it out . The books I would look at buying first are Easy Microcontrol'n and Microcontol'n Apps/ Also check out tutorial 10 on this website http://www.winpicprog.co.uk/pic_tutorial.htm. If you want a specific program written let me know and I will see what I can do? Buy the way also check out www.oshonsoft.com they have excellent pic simulators where you can write the program In MPlab ide then open it up in and see exactley what will happen, has a pretty good range of input and output screens eg lcd, led, 7 seg, switches etc.

Cheers
Greg
Reply With Quote

  #3  
Old 05-27-2009, 09:30 AM
Al_The_Man's Avatar
Community Moderator
 
Join Date: Dec 2003
Location: Canada
Posts: 16,544
Al_The_Man is on a distinguished road
Buy me a Beer?

Also I would have though you would get everything for this off the PicMicro site, all their app notes have sample code?
Al.
__________________
CNC, Mechatronics Integration and Machine Design.
“Logic will get you from A to B. Imagination will take you everywhere.”
Albert E.
Reply With Quote

  #4   Ban this user!
Old 05-27-2009, 11:25 AM
 
Join Date: Mar 2009
Location: Slovenia
Posts: 4
Razer is on a distinguished road
OK

Thank you for the replies!
So here is my code. Note the PIC is a 16F628A becuase I dont have a pic16F84 and am testing it with the newer one. The next thing to notice is that I have some trouble with the TMR0 register so I generated a simple loop to simulate the dalay. If some one has the time I would appreciate the help.
Note allso that I need to make the delay with 16 prescaler and if someone coud explain me what this is.

Code:
list p=16f628a
#INCLUDE <P16F628a.INC>
__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT & _LVP_OFF
  count1	res	1
  count2	res	1
  count3	res	1
  MOVLW 0X07
  MOVWF CMCON
  BSF  STATUS , RP0
  MOVLW b'00000'
  MOVWF TRISA
  MOVLW b'00000000'
  MOVWF TRISB
  BCF STATUS , RP0
;——————————- 
ZACETEK
  MOVLW	b'00111111' ; 0
  MOVWF PORTB
call Delay500mS
  MOVLW	b'00000110' ; 1
  MOVWF PORTB
call Delay500mS
  MOVLW	b'01011011' ; 2
  MOVWF PORTB
call Delay500mS
  MOVLW	b'01001111' ; 3
  MOVWF PORTB
call Delay500mS
  MOVLW	b'01100110' ; 4
  MOVWF PORTB
call Delay500mS
  MOVLW	b'01101101' ; 5
  MOVWF PORTB
call Delay500mS
  MOVLW	b'01111101' ; 6
  MOVWF PORTB
call Delay500mS
  MOVLW	b'00000111' ; 7
  MOVWF PORTB
call Delay500mS
  MOVLW	b'01111111' ; 8
  MOVWF PORTB
call Delay500mS
  MOVLW	b'01101111' ; 9
  MOVWF PORTB
call Delay500mS
  MOVLW	b'01110111' ; A
  MOVWF PORTB
call Delay500mS
  MOVLW	b'01111100' ; b
  MOVWF PORTB
call Delay500mS
  MOVLW	b'00111001' ; C
  MOVWF PORTB
call Delay500mS
  MOVLW	b'01011110' ; d
  MOVWF PORTB
call Delay500mS
  MOVLW	b'01111001' ; E
  MOVWF PORTB
call Delay500mS
  MOVLW	b'01110001' ; F
  MOVWF PORTB
call Delay500mS
  GOTO ZACETEK
  
  Delay500mS

	movlw	.3
	movwf	count1
	movlw	.140
	movwf	count2
	movlw	.82
	movwf	count3

dloop1	decfsz	count3,f
	goto	dloop1
	decfsz	count2,f
	goto	dloop1
	decfsz	count1,f
	goto	dloop1
	return
  END
Reply With Quote

  #5   Ban this user!
Old 05-27-2009, 08:14 PM
 
Join Date: Aug 2008
Location: Australia
Posts: 3
gorders1 is on a distinguished road
Pic

What frequency xtal are you using?

cheers
Greg
Reply With Quote

Sponsored Links
  #6   Ban this user!
Old 05-27-2009, 10:38 PM
 
Join Date: Mar 2009
Location: Slovenia
Posts: 4
Razer is on a distinguished road

Im using the internal oscilator with 4MHz
Reply With Quote

  #7   Ban this user!
Old 06-08-2009, 08:15 AM
 
Join Date: Jun 2009
Location: South Africa
Posts: 3
James Routledge is on a distinguished road

Hi Razer
The way I see it with a crystal of 4Mhz, it gives you a cycle time of 1/(Fosc/4) , or 1uS.
The maximum prescaler available is 256, which will leave the maximum TMR0 timeout at a quarter of a millisecond, not really useful if you want 0.5 seconds.
Added to this, if you want to use timer 0 you will need to use interrupt driven software. At a Microchip seminar one of their inhouse troubleshooting experts said that 90% of PIC firmware problems came from interrupt routines. He advised us to avoid interrupts if at all possible.

I like using delay routines like you have. If you insist on using the TMR0 you'll have to use a prescaler of 256 on a crystal frquency of 2 kHz.

The prescaler is defined in the final 3 bits of the OPTION_REG register and clearing bit 3 of the same register to allocate the prescaler to Timer 0. ( ie your code should place the binary string xxxx0111 in OPTION_REG . you determine what replaces the xxxx according to your software requirements)
Reply With Quote

  #8   Ban this user!
Old 06-09-2009, 05:21 PM
 
Join Date: Aug 2005
Location: U.S.A
Posts: 52
Megahertz is on a distinguished road

James,

What do you mean by ".....which will leave the maximum TMR0 timeout at a quarter of a millisecond"?

Do you mean TMR0 will overflow in a quarter of a millisecond with a 256 prescaler?

I get a different time with my calculations. The timer0 also needs to count to 256 before an overflow.

TMR0 overflow = (1/(Fosc/4))*256*256 = 65.536 milliseconds. The first 256 in the equation is for the prescaler time divider. The second 256 is the actual TMR0 counting from 0 to 256.

~~~~~~~~~~~~~~~~~~~~~~
You could implement this problem using TMR0 and an interrupt service routine.

If you change the prescaler from 256 to 16 you get a TMR0 overflow every 4.096 milliseconds.

TMR0 overflow = (1/Fosc/4))*16*256 = 4.096 milliseconds. Now, if you count the number of TMR overflows to 122 you get a time lapse of about 0.5 seconds. You TMR0 interrupt service routine can count the number of overflows.

Time lapse = 4.096 * 122 = 0.499712 seconds. (0.06 % error)
Reply With Quote

  #9   Ban this user!
Old 06-10-2009, 11:27 AM
 
Join Date: Jun 2009
Location: South Africa
Posts: 3
James Routledge is on a distinguished road

Hi Megahertz.
Thanks for the correction, you're perfectly right.

The point I was trying to get across is that by using a well set up delay routine , Razer would avoid using interrupt routines.

I have avoided using interrupts thus far and always had success.

Thanks for your help.
Reply With Quote

Reply




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
(DAEWOO) Fanuc System 6T with seven segment & LED display?? parametric.ms Fanuc 3 03-26-2010 08:09 AM
Need Help!- Ver. 21 - How to add an end plate to Extruded Curve Segment Sam A BobCad-Cam 5 10-02-2008 10:28 AM
Newbie- Multi Segment Acrylic Telescope Design and mold making Mustafa Umut Glass, Plastic and Stone 0 06-18-2008 07:24 PM
RPM display fatal-exception Mach Mill 0 11-24-2007 03:02 PM
DAKENG u-2 16f84 stepper translator vacpress PIC Programing / Design 2 12-13-2005 07:58 AM




All times are GMT -5. The time now is 03:48 AM.





Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Content Relevant URLs by vBSEO
Template-Modifications by TMS

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 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361