Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC16F627A

Status
Not open for further replies.
If you put the following at the beginning of your code You will be able to use words like TRISB, PORTB , STATUS etc.

list P=16f627
#include "p16f627a.inc"
__config _HS_OSC & _WDT_OFF & _PWRTE_ON & _LVP_OFF
The #include does this.
The _config sets the type of oscillator to be used for the system clock

As you are using a 20 MHZ crystal the instruction cycle time will be 200 nS (4 cycles of 20 MHZ)
As the BSF instruction takes 1 system clock cycle the LEDs will only be on for 200 nS

The reason for the stack overflow is because you do not have a return instruction at the end of your delay subroutine.
Also you either have to jump past the delay subroutine to get to the main program loop or move the delay routine to the end of the code.
The logic of your program will not do what has been specified.
Your delay routine needs to either contain a loop to count a lot of instructions or use one of the timers to produce a delay. Note 1 second delay requires 5000000 instruction cycles.
If you are counting instruction cycles bear in mind that some instructions take more than 1 instruction cycle.

Les.
 
I AM WINNING, I WON'T SLEEP UNTIL I GET THIS DONE, I SAID I WANT TO LIVE ARTIFICIAL INTELLIGENCE LIFE AND SO THAT'S WHAT I'LL DO.
 
I'm afraid I don't understand the Lab assignment, either.

When I was at University a few years ago, my instructors were very receptive to emails asking to clarify Lab assignments.
 
Sir Jpanhalt, how and where do i put the code in conjuction with my source code... it gives me some errors.
You need to re-read the last paragraph of my comment. As I understood the sequence of events, you ask about a 1 second delay. I told you how to get code for doing that. I also said that is not the way I would do it.

I assume this is not the fist problem in a programming class. Had you heard of the "include" directive? Have you learned the btfss and decfsz instructions?

John
 
Mr Nigel Goodwin, how would the circuit diagram of Tutorial 1.3 look like? I wanna build the circuits now; Or just anyone of you members?
 
Tumelo,
Could your instructor be trying to create a real word situation for you. The customer does not give a very precise description of the requirement. You would need to go back to the customer to clarify the requirement. (In you case your instructor.) The customer may have specified the use of a micro controller that you have not used before so your instructor is testing how well you read the data sheets and convert the specifications into a working product. If the instructor has only given you a few days for this project the he is being unreasonable. If you have had the project for some time and not looked at it until a few days before the deadline then that's your own fault.

Les.
 
And of course, one real world lesson is that if you are not on time, you may lose the customer, which in this case may be translated into flunking the class.

Tumelo When is it really due(GMT)? What processor speed do you plan to use? What have you gotten done so far?

John
 
Hi all. I thank the administrators of this forum for providing us with this platform and I thank the philanthropists herein. Judging by the (IIE20BT...).doc file attached by Tumelo, surprisingly we happen to be from the same school and even same class.
After going through these posts i've started to see the light on the other end of the tunnel.

Will someone please help me use the time delay formular to get a 1 second delay for two blinking LEDs. TIC = 1 + 3xyz + 4xy + 4x

Thank you
 
You really only have to delay for 250mS

Code:
main
   TRISB = 1
   call routine
   TRISB = 2
   call routine
   goto main

routine
   PORTB = 0
   delay 250mS
   PORTB = 3
   delay 250mS
   PORTB = 0
   delay 250mS
   PORTB = 3
   delay 250mS
   return
end

lets assume a 4Mhz crystal ( Internal speed )

To get 250mS with a 4Mhz crystal.. Each clock is 1uS
with a 16 bit timer running at 1:1 65535uS is 65.535mS..
with a pre-scale of 1:4 you will get 262mS...

If you preload the timer with 3536, this will get you 250mS..
If you need to make a delay routine instead of using the timer
you need to count to 250000...
 
Travis22,
jpanhalt has given you one way to create a delay of 1 second in his post #17 this is using a 4 MHZ crystal for timing. If you are using a different clock frequency you will have to change the loop counters (d1, d2,d3) There are many ways to create the delay. I have no idea what your equation "TIC = 1 + 3xyz + 4xy + 4x" means without you defining what TIC, x,y,z are. It would be easy for any one of us to write the code but that would not achieve anything. If none of you in the class can write the code then it will show the teaching is at fault.

Les.
 
Dear students .... Just for this exercise why not run the Pic from an external 32.768 khz watch crystal , then timer 0 will do an accurate 1 Sec easy....
 
Last edited:
A few of us have asked why a 1-second delay is needed or even desired. It would be nice if either student would present a flowchart showing where that delay is involved. That way, it might be made clearer to the students how to do the assignment more simply using just one delay.

John
 
HELLO EVERYONE, I HAVE DIFFICULTIES CONNECTING THE PIC16F627A AND 2 LED'S ON MY BREADBOEARD. I HAVE TWO LED'S, ONE BREAD BOARD, RESISTORS AND WIRES... I HAVE TRIED ALL SORTS OF CONNECTIONS BUT I STILL CAN'T GET IT RIGHR. MY CODE IS IN ASSEMLY LANGUAGE... PLEASE ASSIST ME ANY HOE YOU COULD.(MY CONNECTION... I PUT +V TO PIN 14, -VOL TO PIN 5; I CONNECTED LED1 ANODE LEG TO RB0, LED2 ANODE TO RB1(WITH WIRES), BUT IT STILL NOT WORKING)
 
What oscillator configuration are you using. Do you have a line of code to configure the oscillator ?
Similar to this __config _HS_OSC & _WDT_OFF & _PWRTE_ON & _LVP_OFF (This configures the chip to use a high speed crystal.)

Les.
 
If you have the same version of the data sheet on the PIC16F627 as me then look at pages 95 & 96. If you have a different version then search for " CONFIGURATION WORD REGISTER" and "Oscillator Configurations" This will give you the information to configure the oscillator type you plan (Or have been told) to use. If you chose a 32.768 KHZ crystal (As I think someone has already suggested) then you do not need to divide by a very large number.

Les.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top