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.

[SOLVED] PIC complete discussion for all

Status
Not open for further replies.
guys did I missed something?
It's working in protues but in real hardware is not working..

Im using internal clock of PIC16f628
how do I add config bits for that? I dont know the syntax


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
#include<pic.h>
 
 
__CONFIG(WDTDIS & UNPROTECT);
 
void main()
{
   
   unsigned int x;
   TRISA2 = 0;
   PORTA = 0;
   
  
   while(1)
   {
   
      
     
      RA2 = 0;
      for(x=0; x<1000; x++);
      RA2 = 1;
      for(x=0; x<1000; x++);
 
      
   }
}

 

__CONFIG(0x3F3A);

---------- Post added at 12:46 ---------- Previous post was at 12:44 ----------

In MPLAB, click configure >> configuration bits
There you can get the value according to your need.
 
__CONFIG(0x3F3A);

---------- Post added at 12:46 ---------- Previous post was at 12:44 ----------

In MPLAB, click configure >> configuration bits
There you can get the value according to your need.

that is in the datasheet. right?

I will try to add that line now because it's weird the led is not blinking if i will not touch the positive line... LOL
 

I am not telling 3F3A is the required configuration value for your PIC.
Wait, let me open MPLAB and check suitable value for your PIC.
 

I think this will work in your case.

__CONFIG(0x3F2A);

yes it works for External oscillator.. thanks..

I think I spent more than 1 hour just to set up the fuse bits for internal oscillator but it did not work.. hehe

this site is very nice . after I read this I manage to get it working..
Oscillator of PIC16F628

i use this __CONFIG(0x3F38); to use the internal clock... now it's working in hardware.. hehe thanks guys..

today i learned to program PIC and to set config bits.. :)
 

I find it hard using PIC micro-controller than 8051 microcontroller.. :cry:

I worked before with 8051 families and if I have delay routines of one microcontroller let say 20pin 8051 I can apply it to 40pin 8051. its basically the same..

how about in PIC? PIC is very complicated for me I think...

can I use the same delay with PIC16f628 to PIC16f77A?
 

in high tech C there is inbuild delay routines...

---------- Post added at 15:52 ---------- Previous post was at 15:49 ----------

use
#define _XTAL_FREQ 20e6
(if 20MHz or edit that accordingly)
Now
Use
__delay_ms( );
Or
__delay_us( );
 
in high tech C there is inbuild delay routines...

---------- Post added at 15:52 ---------- Previous post was at 15:49 ----------

use
#define _XTAL_FREQ 20e6
(if 20MHz or edit that accordingly)
Now
Use
__delay_ms( );
Or
__delay_us( );


can I use that directly without including any .h file?
I have also the delay from microchip website but there are many files to include just for simple delay..
 

thanks... is it accurate?

where I can check the inbuilt functions of hi-tech C? so that I will know and use them.
 

Re: [HELP] Questions About HITECH-C compilers and PICprogramming

hi Im back again.. I think this thread needs to edit the title..

I have question again guys.. IM now learning how to use the timer0 of PIC..

I have question about the prescaler.. I read the datasheet but i cant absorb it fully.. Is there any explanation other than the definition in the datasheet?



OPTION_REG = 0b0111; // prescale by 256

as I understand
PSA is assigned to timer0

PS2,PS1,PS0 is set to high to have a value of 256(according in the table)..

but why use this notation 1:256 ?? what does it mean?
what exactly the function of prescaler?

TOCS = 1 or 0 //clock source select bit.
does it mean if I set this to high I will need an external oscillator?


here is the code:
PHP:
void interrupt timer0_isr(void)
{
	if(reload == 0)
    {
		// effect a change on PORTB whenever our desired period is reached.
		// Note this timing will contain a margin of error.
		reload = RELOADS + 1;
		seconds++;
		PORTB++;	// effect a change on PORTB
	}
	reload--;
	T0IF = 0;
}


main()
{
	// initialize timer 0; 
	
	OPTION_REG = 0b0111;	// prescale by 256
	T0CS = 0;			// select internal clock
	T0IE = 1;			// enable timer interrupt
	GIE = 1;			// enable global interrupts
	TRISB = 0;			// output changes on LED
	
	for(;;)
		continue;		// let interrupt do its job
}
 
Last edited:

Hi romel
Nice to see you again and trying hard to learn things well..

http://www.sxlist.com/techref/microchip/timer.htm
Read this (pages194 &195)....**broken link removed**

Both prescaler and post scaler are used to get our desired frequency from a basic reference.

The prescaler divides the ref frequency by some speific factor( that is entered into the clock register/ PLL register) and thus helps in reducing the frequency.


The CPU clock speed is the oscillator speed divided by four. In your case this is 4MHz/4 so if TMR0 counts 1:1 on internal clocks its increment rate is once every usec (1MHz). The TMR0 increment rate is futher divided by the prescaler. You need to consider the PSA bit also, it assigns the prescaler to the WDT or to TMR0.

TMR0 increment = Oscillator/4/prescale.
Are you looking at the description of the OPTION register in section 4.2.2.2 ? There's no need to guess, it clearly shows that 101 gives you a 1:64 prescaler option.
Maybe you are looking at the right-most column, which shows you would get 1:32 if the prescaler was assigned to the watchdog timer.
 
The CPU clock speed is the oscillator speed divided by four
hi ckshivaram, I understand now but needs more clarification about the theory..

why divided by 4? Is it because the PSA is 4bits?
 

wait I get confused in math side :) hihi I hate numbers.. pls help

fosc means oscillator(crystal) frequency. right?

then

let say I have 4mhz crystal

4mhz / 4 crystal cycles / prescaler of 2 = 0.5usec
---- correct?

my plan is to generate 50ms from that then then multiply to 20 so that I can have a delay of 1sec.. is it possible??
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top