SK40C Beginner

Discussion about projects that used PIC Microcontroller, Hardware Interface, Programming Algorithm and etc......

Re: SK40C Beginner

Postby vick5821 » Mon Mar 05, 2012 1:08 pm

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
vick5821
Discoverer
 
Posts: 85
Joined: Tue Jun 28, 2011 10:21 pm

Re: SK40C Beginner

Postby ABSF » Tue Mar 06, 2012 8:45 am

Show us your latest code.

Allen
The next war will determine NOT who is right BUT what is left.
User avatar
ABSF
Professional
 
Posts: 810
Joined: Wed Nov 10, 2010 9:32 am
Location: E Malaysia

Re: SK40C Beginner

Postby vick5821 » Wed Mar 07, 2012 6:30 pm

CODE: SELECT_ALL_CODE
#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
   }   
}


My latest code :)
vick5821
Discoverer
 
Posts: 85
Joined: Tue Jun 28, 2011 10:21 pm

Re: SK40C Beginner

Postby robosang » Wed Mar 07, 2012 8:42 pm

But you din include the system.h in your code. Why do you need to include htc.h and do not need to include system.h?
robosang
Expert
 
Posts: 1239
Joined: Wed Jun 10, 2009 5:37 pm

Re: SK40C Beginner

Postby vick5821 » Wed Mar 07, 2012 9:03 pm

why system.h ?Is this compulsary for each coding ?

Thank you
vick5821
Discoverer
 
Posts: 85
Joined: Tue Jun 28, 2011 10:21 pm

Re: SK40C Beginner

Postby vick5821 » Thu Mar 08, 2012 10:27 pm

hey I am confused here

Can I use for loop in my code ? or I can just use while(1) ?

Because last time some of you said if I put for and not infinite loop it will cause the unwanted LED to blink dimly a while ?
vick5821
Discoverer
 
Posts: 85
Joined: Tue Jun 28, 2011 10:21 pm

Re: SK40C Beginner

Postby ABSF » Fri Mar 09, 2012 11:29 am

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. :mrgreen:

Allen
The next war will determine NOT who is right BUT what is left.
User avatar
ABSF
Professional
 
Posts: 810
Joined: Wed Nov 10, 2010 9:32 am
Location: E Malaysia

Re: SK40C Beginner

Postby vick5821 » Fri Mar 09, 2012 2:27 pm

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. :mrgreen:

Allen

CODE: SELECT_ALL_CODE
#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
   }   
}


This is my latest code and below is the error I get when compile it:
Image

If I add system.h , this is another error that it will be :
Image

So how ?

If I use this delay function it is ok.
CODE: SELECT_ALL_CODE
void delay(unsigned long data) //delay function, the delay time
{
for( ;data>0;data-=1); //depend on the given value
}


How to use the delay_ms function ? any header needed ?

Thank you
vick5821
Discoverer
 
Posts: 85
Joined: Tue Jun 28, 2011 10:21 pm

Re: SK40C Beginner

Postby ABSF » Fri Mar 09, 2012 5:47 pm

Corrected code.

CODE: SELECT_ALL_CODE
#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);
}
}

Allen
The next war will determine NOT who is right BUT what is left.
User avatar
ABSF
Professional
 
Posts: 810
Joined: Wed Nov 10, 2010 9:32 am
Location: E Malaysia

Re: SK40C Beginner

Postby robosang » Fri Mar 09, 2012 5:51 pm

system.h is just a header file like htc.h. Why must be system.h? No special reason except you write some code in that file and you need it in your main file. As allen pointed out, if you don like to include system.h you can write all the needed code on your main file.


BTW, "system" is just a name given to a file, is a file name, you want to write your name as the file name also no problem, but you need to let your main file know where is the file? Must through the correct file name.
robosang
Expert
 
Posts: 1239
Joined: Wed Jun 10, 2009 5:37 pm

PreviousNext

Return to PIC Microcontroller

Who is online

Users browsing this forum: No registered users and 0 guests

cron