SK40C Beginner

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

Re: SK40C Beginner

Postby vick5821 » Fri Feb 17, 2012 10:45 am

This is my code :

CODE: SELECT_ALL_CODE
#include <pic.h>

__CONFIG(FOSC_HS &    // High Speed Crystal.
WDTE_OFF &    // Disable Watchdog Timer.
PWRTE_ON &    // Enable Power Up Timer.
BOREN_OFF &    // Disable Brown Out Reset.
MCLRE_ON & // Enable MCLR
LVP_OFF);    // Disable Low Voltage Programming.

#define sw1 RB2
#define sw2 RD2
#define LED_1 RB0
#define LED_2 RB1


void init(void);
void delay(unsigned long data);

void main(void)
{

init();
LED_1=0;
LED_2=0;


if (sw1==0)
{
PORTB=0b00000001;
delay(100000);
PORTB=0b00000000;
delay(100000);
PORTB=0b00000010;
delay(100000);
PORTB=0b00000000;
delay(100000);
}

if (sw2==0)
{


LED_1=0;
LED_2=0;
LED_1=1;
LED_2=1;
delay(10000);
LED_1=0;
LED_2=0;
delay(10000);
LED_1=1;
LED_2=1;
delay(10000);
LED_1=0;
LED_2=0;

}
}


void init()
{
TRISA=0b00000000;
TRISB=0b00000100;
TRISC=0b00000000;
TRISD=0b00000100;
TRISE=0b00000000;
}

void delay(unsigned long data) //delay function, the delay time
{
for( ;data>0;data-=1); //depend on the given value
}


And when I load it into my SK40C, then power on, the LED gives me a dim light and the program doesnt work as expected..sometimes the dim light will gone when I slightly moved my SK40C :(

Any problem ?

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

Re: SK40C Beginner

Postby ABSF » Fri Feb 17, 2012 1:33 pm

The SK40C has 2 switches connected to RB0 & RB1 and 2 LED connected to RB6 & RB7. Try read the schematics before you connect any sw or LED to the board. There might be HW conflict so it acted weird.

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 Feb 17, 2012 8:08 pm

Allen is right, SK40C come with 2 switches connected to RB0 and RB1. It is being labeled near the switches.

connecting the LED at RB1 and RB0 will have dim effect because if it being pulled up via resistor. You can actually use the ready LEDs at RB7 and RB6 as suggested by Allen.
robosang
Expert
 
Posts: 1239
Joined: Wed Jun 10, 2009 5:37 pm

Re: SK40C Beginner

Postby vick5821 » Sun Feb 19, 2012 11:47 pm

CODE: SELECT_ALL_CODE
#include <pic.h>

__CONFIG ( 0x3732 );

#define LED_1 RC3
#define LED_2 RC2


void init(void);
void delay(unsigned long data);

void main(void)
{
init();

LED_1=0;
LED_2=0;
for(int i=0;i<10;i++)
{
LED_1=0;
LED_2=0;
delay(10000);
LED_1=1;
LED_2=0;
delay(60000);
LED_1=0;
LED_2=1;
delay(60000);
}



LED_2=0;
delay(100000);
for(int j=0;j<4;j++)
{
LED_1=1;
LED_2=1;
delay(100000);
LED_1=0;
LED_2=0;
delay(100000);
LED_1=1;
LED_2=1;
}


}



void init()
{
TRISA=0b00000000;
TRISB=0b00000000;
TRISC=0b00000000;
TRISD=0b00000000;
TRISE=0b00000000;

}

void delay(unsigned long data) //delay function, the delay time
{
for(;data>0;data-=1); //depend on the given value
}


This is my coding and below is the video.Observe @0.24s
http://www.youtube.com/watch?v=azBEDpipFTg&feature=youtu.be

I would like to ask, why after the LED_1 and LED_2 blink for four times, when it start again the loop, the blue light which is connected to RC2 will lights up abit then off , then it just to start over again ?

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

Re: SK40C Beginner

Postby robosang » Mon Feb 20, 2012 11:01 am

Reset, PIC reset! You need to have an infinite loop for example
while(1);
before the end of main, this will prevent PIC from reset itself because running out of code to execute :lol:
robosang
Expert
 
Posts: 1239
Joined: Wed Jun 10, 2009 5:37 pm

Re: SK40C Beginner

Postby vick5821 » Mon Feb 20, 2012 11:33 am

Hey, what does RESET means actually in PIC ? I used 'for' loop .I cant use for loop in PIC ? It must be inifnite loop once it started ?
vick5821
Discoverer
 
Posts: 85
Joined: Tue Jun 28, 2011 10:21 pm

Re: SK40C Beginner

Postby vick5821 » Mon Feb 20, 2012 3:02 pm

Hey ober, why my LED at RB6 and RB7 seems weird ? Cant be program ?

I get frustated in programming all this as I cant find a proper programming tutorial for PIC :(

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

Re: SK40C Beginner

Postby hyng » Mon Feb 20, 2012 5:00 pm

vick5821 WROTE:Hey, what does RESET means actually in PIC ? I used 'for' loop .I cant use for loop in PIC ? It must be inifnite loop once it started ?

Normally we will put an infinity loop else the pic will reset. Of course you can use loop. Isn't there a sample code given in the SK40C page. You may follow the format.

vick5821 WROTE:Hey ober, why my LED at RB6 and RB7 seems weird ? Cant be program ?

I get frustated in programming all this as I cant find a proper programming tutorial for PIC :(

Thank you

what is going wrong with your LEDs at RB6 and RB7? pls explain further. If you want to test on the LEDs at RB6 and RB7. Please load the sample source code (hex file) to the SK40C. The sample code is a LED blinking on RB6 and RB7. And see if it is work.
User avatar
hyng
Moderator
 
Posts: 292
Joined: Thu Apr 16, 2009 11:35 am

Re: SK40C Beginner

Postby robosang » Mon Feb 20, 2012 6:37 pm

Give up so fast? It take me few weeks to get a single LED blinking when I started to play with PIC. There is no low cost programmer like UIC00B from Cytron, no starter kit, no sample code in C, no sample circuit.

Well, I did it now, though not expert like other, but I manage to do what I want 8-) Even now, I am still learning, everyday I make mistake, I need to check datasheet why I/O pin cannot work, why ADC cannot read correct data, etc. I am sure other have similar problem, but we solve it.
robosang
Expert
 
Posts: 1239
Joined: Wed Jun 10, 2009 5:37 pm

Re: SK40C Beginner

Postby Brian Griffin » Mon Feb 20, 2012 7:16 pm

robosang WROTE:Give up so fast? It take me few weeks to get a single LED blinking when I started to play with PIC. There is no low cost programmer like UIC00B from Cytron, no starter kit, no sample code in C, no sample circuit.

Well, I did it now, though not expert like other, but I manage to do what I want 8-) Even now, I am still learning, everyday I make mistake, I need to check datasheet why I/O pin cannot work, why ADC cannot read correct data, etc. I am sure other have similar problem, but we solve it.


It takes a day or a two for me to get the LED on using PIC16F assembly, but to calculate the delays in software - weeks.

Then, the rest of the peripherals - more weeks.

That was in 2008. I learned it during sem break. And even on weekends when I have nothing to do, or when I can't sleep. (I'm a minor insomniac here) :lol:

P.S: Getting the FreeRTOS working on the PIC32 - 10 weeks. And that's the simple example! :oops: So be patient when learning programming!
PIC - UIC00B from Cytron (replacement for my broken PICKit 2), Pickit 3, MikroC for PIC
dsPIC - MikroC for dsPIC, mikromedia board (dsPIC33)
AVR - AVR Dragon
Parallax - Prop tool
User avatar
Brian Griffin
Enthusiast
 
Posts: 403
Joined: Mon Jan 17, 2011 9:36 am

PreviousNext

Return to PIC Microcontroller

Who is online

Users browsing this forum: No registered users and 4 guests