isnt that the hearder system.h is a library that define the lighting sequence of the 7 segment ? It includes the XTAL_FREQ too ?
Thank you
#include <htc.h>
__CONFIG(0x3F32);
void delay_ms(unsigned int ui_value);
void main(void)
{
PORTA=0;
PORTB = 0;
PORTC = 0;
PORTD = 0;
PORTE = 0;
TRISA = 0x00;
TRISB = 0x00;
TRISC = 0x00;
int num;
PORTC =0b0011111;
delay_ms(2000);
PORTC = 0b00000110;
delay(2000);
}
void delay_ms(unsigned int ui_value)
{
while (ui_value-- > 0) {
__delay_ms(1); // macro from HI-TECH compiler which will generate 1ms delay base on value of _XTAL_FREQ in system.h
}
}
vick5821 WROTE:why system.h ?Is this compulsary for each coding ?
Thank you
ABSF WROTE:vick5821 WROTE:why system.h ?Is this compulsary for each coding ?
Thank you
No, it is not compulsary but it is the easiest way to solve your problem for now and in time to come as you are doing 7-segment LED display project. It might be needed later.
If you insist not to include the "system.h" header file. You may add the line "#define _XTAL_FREQ 20000000" to the beginning of your program and it should work. Try it out.![]()
Allen
#include <htc.h>
__CONFIG(0x3F32);
#define _XTAL_FREQ 20000000;
void delay_ms(unsigned int ui_value);
void main(void)
{
PORTA=0;
PORTB = 0;
PORTC = 0;
PORTD = 0;
PORTE = 0;
TRISA = 0x00;
TRISB = 0x00;
TRISC = 0x00;
PORTC =0b0011111;
__delay_ms(2000);
PORTC = 0b00000110;
__delay_ms(2000);
}
void delay_ms(unsigned int ui_value)
{
while (ui_value-- > 0) {
__delay_ms(1); // macro from HI-TECH compiler which will generate 1ms delay base on value of _XTAL_FREQ in system.h
}
}
void delay(unsigned long data) //delay function, the delay time
{
for( ;data>0;data-=1); //depend on the given value
}
#include <htc.h>
__CONFIG(0x3F32);
#define _XTAL_FREQ 20000000
void delay_ms(unsigned int ui_value);
void main(void)
{
PORTA=0;
PORTB = 0;
PORTC = 0;
PORTD = 0;
PORTE = 0;
TRISA = 0x00;
TRISB = 0x00;
TRISC = 0x00;
PORTC =0b0011111;
delay_ms(2000);
PORTC = 0b00000110;
delay_ms(2000);
}
void delay_ms(unsigned int ui_value)
{
while (ui_value-- > 0) {
__delay_ms(1);
}
}
Users browsing this forum: No registered users and 0 guests