[SOLVED] PIC complete discussion for all

Status
Not open for further replies.
Can't you sleep?

Setting CMCON = 0x07, basically disables the comparator section. Take a look at the first diagram you posted above, "Comparators Off CM2:CM0=111".

Then if you look at each pin diagram on PORTA and realize the comparator section is off/disable then MOST of the PORTA pins behave like PORTB pins and require the same initialization as a PORTB pin, with the exceptions being RA4 and RA5, as well as, RA6 and RA7 if an external OSC is used.

Ciao

---------- Post added at 00:13 ---------- Previous post was at 00:10 ----------

By the way, many of the 16F series PIC, require disabling the ADCs analog inputs before using any PORTA pins as digital i/o. While this particular model requires disabling the comparator section.
 
Can't you sleep?
yes.. Im very eager to learn.. :x

with the exceptions being RA4 and RA5

RA5 is MCLR it is one direction only and cannot use as output.
so after disabling the comparator I can noW use the RA4 with external pull up..right? ..


thanks to you guys answering my doubts... your the best!!
 

RA5 is MCLR it is one direction only and cannot use as output.

Correct.

so after disabling the comparator I can noW use the RA4 with external pull up..right? ..

Yes and No, its an open drain output, so it can sink current, but not source it.

So, if you want to attach an LED, you would tie the LED cathode to the RA4 pin and the LED anode to a current limiting resistor, say 220Ω to 470Ω to the Vdd (+5v).

You would turn on the LED by setting the RA4 pin to '0', turn it off by setting RA4 to '1'.

¿Comprende?
 
Also, remember after disabling the comparators, you still need to specify the direction of the digital i/o on PORTA with TRISA register.

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

Have you figured out what the problem was with your interrupt routines?
 
need to specify the direction of the digital i/o on PORTA with TRISA register.

ok.. sure.. thanks for reminding.. I will test it directly in the hardware because I cannot get assurance in the simulator.
 

I found this tutorial page showing open collector outputs which are somewhat similar in behavior to open drain outputs like RA4:

PIC Tutorial Hardware - Open Collector Outputs

Some tutorials with 16F628 specific source code:

WinPicProg PIC Tutorials - PIC16F628

I came across the tutorials above, you probably have already checked them out, they are PIC16F628 specific.

Let me know if you need any more help with your ISRs.

Ciao
 

thanks.. though the example codes were in assembler(afraid of assembler) but I will read the tutorial..
 

this is totaly F***.. hehe :x :-D This is UNreal!!! I dont believe this..!!! haha

still dont work.. I will try another things other than this..



I Figured out the reason why things dont work.. I cannot use all the conditional statement like while(), if(). etc...
I dont know why this is happening... any idea? interrupt is working but if I use any of the conditional statement inside the interrupt or the main fucntion it will not work anymore..




PHP:
#include<htc.h>


__CONFIG(INTIO & WDTDIS & PWRTEN & MCLREN & BORDIS & DATUNPROT & UNPROTECT);



char count;
void interrupt timer0_isr(void)
{

	
	T0IF = 0;
	PORTA++;
	count++;
}

main()
{
	// initialize timer 0; 
	
	OPTION = 0b0111;	// prescale by 256
	T0CS = 0;			// select internal clock
	T0IE = 1;			// enable timer interrupt
	GIE = 1;			// enable global interrupts
	CMCON = 0x07;
	TRISB = 0b00000000;			// output changes on LED
	TRISA = 0b00000000;
	
	while(1)
	{
	

			if(PORTA > 1)
			PORTB++;
	
	}
}

I Figured out the reason why things dont work.. I cannot use all the conditional statement like while(), if(). etc...
I dont know why this is happening... any idea?

---------- Post added at 12:29 ---------- Previous post was at 12:17 ----------

guys.. pls compile this code for me and give me the hex.. tnx

In real hardware LED attached in port A is working.. and because I cant use any conditional statement LED attached in PORTB does not work.. pls compile this code and give me the hex..


PHP:
#include<htc.h>


__CONFIG(INTIO & WDTDIS & PWRTEN & MCLREN & BORDIS & DATUNPROT & UNPROTECT);



char count;
void interrupt timer0_isr(void)
{

	
	T0IF = 0;
	PORTA++;
	count++;
	if(count > 16)
	{
		count = 0;	
		PORTB++;
	}
}

main()
{
	// initialize timer 0; 
	
	OPTION = 0b0111;	// prescale by 256
	T0CS = 0;			// select internal clock
	T0IE = 1;			// enable timer interrupt
	GIE = 1;			// enable global interrupts
	CMCON = 0x07;
	TRISB = 0b00000000;			// output changes on LED
	TRISA = 0b00000000;
	
	while(1);

}


---------- Post added at 13:23 ---------- Previous post was at 12:29 ----------

Im buying PIC16f877a today.. hehe
 

I cannot use all the conditional statement like while(), if(). etc... I dont know why this is happening
Sounds unlikely.

You have several places in your code, where I/O ports are either read in or undergo a read-modify-write operation, e.g. PORTA++. To understand the result, it's necessary to know the external connections of all involved I/O pins. If one is e.g. interfacing a LED without or with a too low current limiting resistor, readback of the port value may fail.

This problems can be of course overcome by not reading back the port data, using an internal variable instead, that's only writen to the port.
Code:
PORTA=Astate++;
 
Hi FvM..

my big problem is why I cannot use conditional statement? I tried everything to increment a variable but no luck..

PLs consider this example:

If i will remove the if statement LED attached at PORTB will work..its very weird...

and if I will place that condition inside the main fucntion it still dont work untill I remove the if statement


can you compile my code above and return to me the hex file?

PHP:
int count = 0;
void interrupt timer0_isr(void)
{

    
    T0IF = 0;
    PORTA++;
    count++;
    if(count > 16)
    {
        count = 0;    
        PORTB++;
    }
}
 

can you compile my code above and return to me the hex file?
Unfortunately, I don't use the Hitech-C compiler.

I still don't understand which problem should be brought up by using if() in the code.
 
ok.. what is your compiler anyway?

---------- Post added at 15:56 ---------- Previous post was at 14:12 ----------

haha finaly it worked!!!!! hahaah Im now happy!!

HI-TeCH C was the Culprit I downgraded it to v9.80...


PHP:
#include<htc.h>


__CONFIG(INTIO & UNPROTECT & DATUNPROT & LVPDIS & BORDIS & MCLREN & PWRTEN & WDTDIS);



char count;
void interrupt timer0_isr(void)
{

    
    T0IF = 0;
    PORTA++;
    count++;
    if(count > 16)
    {
        count = 0;    
        PORTB++;
    }
}

main()
{
    // initialize timer 0; 
    
    OPTION = 0b0111;    // prescale by 256
    T0CS = 0;            // select internal clock
    T0IE = 1;            // enable timer interrupt
    GIE = 1;            // enable global interrupts
    CMCON = 0x07;
    TRISB = 0b00000000;            // output changes on LED
    TRISA = 0b00000000;
    
    while(1);

}
 

Im also done with timer1 interrupt.

I may sleep now.

after 6 hours I will try the serial communication..

by the way.. in 8051 it is called UART and in PIC USART.. based on some site I read about they are both the same.. right?
 

Last edited:
hi


they are same....... only thing is configuring them and using them is different...

what do you mean by this? you mean the configuration bits?
I just pasted same code and it worked
 

by the way.. in 8051 it is called UART and in PIC USART.. based on some site I read about they are both the same.. right?

The difference between UART ( Universal Asynchronous Receiver Transmitter ) and USART (Universal Synchronous Asynchronous Receiver Transmitter ) is obviously the word "Synchronous."

Without getting too technical, synchronous data transmission requires both separate data and clock lines, while Asynchronous just a data line.

The USART supports both.

I have more detail docs on the subject, I'll post links later today.


haha finaly it worked!!!!! hahaah Im now happy!!

HI-TeCH C was the Culprit I downgraded it to v9.80


Well, I'm glad you finally got your code to compile and run successfully!

I've been using Hi-Tech C Pro v9.81 for some time now, without any problems as yet. It sounds like a corrupt installation or a drive integrity problem, any other programs giving you trouble?

Have you done any hard drive maintenance lately, defragmentation, error scanning, etc. Scanned for viruses lately?

Are you downloading the Hi-Tech C installation directly from Microchip or Hi-Tech?

Ciao
 
Have you done any hard drive maintenance lately, defragmentation, error scanning, etc. Scanned for viruses lately?

yeah... I just remember now I did disk clean up and delete all the temporary files in my drive C... :grin: I think that caused the problem


any other programs giving you trouble?
as of now, None.. ..

Are you downloading the Hi-Tech C installation directly from Microchip or Hi-Tech?
Im using before the bundled HI-TECH C from mplab. and myv 9.80 was from htsoft.com
 

Here's a fairly good example of implementing synchronous data transmission between a PIC and a MCP2122 (IR encoder/decoder) using the PIC's USART:

Interfacing the MCP2122 to the Host Controller

If you look at the block diagram, you'll not only see SO/TX and SI/RX lines established between the PIC and MCP2122, but a CLK line as well.

Here's a PDF discussing the USART's two different modes, synchronous and asynchronous:

Serial Port Utilities

Hope the info helps answer your question.

Ciao

---------- Post added at 18:39 ---------- Previous post was at 18:31 ----------

You, may want to upgrade MPLAB to v8.70, I was having problems with stability of the IDE, MPLAB v8.70 seemed to correct those problems:

**broken link removed**

**broken link removed**

I understand Microchip is releasing a Java based IDE, similar to or based on Eclipse, MPLAB X. I downloaded the beta, but haven't had the time to install it.

It should be interesting!

Ciao
 

I understand Microchip is releasing a Java based IDE, similar to or based on Eclipse, MPLAB X. I downloaded the beta, but haven't had the time to install it.


Good morning to me.

I tried MPLAB X in linux and the auto complete feature of that IDE is awesome!! BUT some stability issue in my experience the compiler is very slow and sometimes crashed.... sad....maybe it still in BETA.. but maybe the windows version is good.

---------- Post added at 23:28 ---------- Previous post was at 23:20 ----------

You may try this if you have time..


**broken link removed**

---------- Post added at 23:30 ---------- Previous post was at 23:28 ----------

and here is the FAQ about MPLAB X

MPLAB X IDE - Microchip Technology

---------- Post added at 23:42 ---------- Previous post was at 23:30 ----------

But I don't Like the system equirement of MPLAB X ..maybe because it's java version

**broken link removed**


compare to MPLAB even your 20 year old PC can handle to compile your project.

**broken link removed**
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…