P0 User Manual

download P0 User Manual

of 3

Transcript of P0 User Manual

  • 8/13/2019 P0 User Manual

    1/3

    PROJECT 0My 1st IC ROJECT, LOAD A SIM LE LED BLINKIn this project, we are going to do a simple LEDs

    blinking using the LEDs on SK40C In here, we are

    using both o! the LEDs and blink it like a police car

    "esides on learning electronic parts, #ou will also

    learn about some coding in C using $I%&EC$ C in

    '(L)"

    COM ONENT NEEDED

    LEDs *+ SK40C

    CONNECTIONor this project, the LEDs was alread# connected to

    the pins -"./(*-&". and -"1/(*-&"1 So, #ou

    ma# onl# ha2e to con!igure the I3* pins as an output

    in programming part &o program the (IC.551,

    connect the 6IC00" to the ICS( (rogrammer 'ake

    sure the power connection is correct and *+ !or

    SK40C *pen '(L)" and include the (roject70c and

    click to compile and build $E8 !ile )!ter 9"uildSuccess!ul:, the (ICKit; should automaticall# run and

    program the $E8 !ile into (IC.551 inall#, the

    LED and LED; will be blink like the police car

    CODE OVERVIEWConfiguration for PIC16F887

    igure below shows the Con!iguration !or (IC.551

    &he code abo2e can be !ound at the Con!iguration

    bits /C*+ID&DIS >atchdog &imer Disable

    (>-&E+ (ower 6p &imer Enable

    "*-DIS "rown *ut -eset Disable

    'CL-E+ 'CL- unction Enabled

    L?(DIS Low ?oltage (rogramming Disable

    http://ww1.microchip.com/downloads/en/DeviceDoc/41291D.pdfhttp://ww1.microchip.com/downloads/en/DeviceDoc/41291D.pdfhttp://ww1.microchip.com/downloads/en/DeviceDoc/41291D.pdf
  • 8/13/2019 P0 User Manual

    2/3

    system.h

    @de!ine78&)L7-EA ;0000000"esides that, same step b# @de!ine the cr#stal

    !reBuenc#/78&)L7-EA according to #our e=ternal

    cr#stal !reBuenc# using In here, the de!ault e=ternal

    cr#stal !reBuenc# using are ;0000000 /;0'$

    @de!ineS> -"0

    In here, we ha2e alread# de!ine the switch on SK40C

    board as -"0 6ser are no need to de!ine again in the

    main coding

    @de!ineLED -".

    In !igure abo2e, using the code @de!ine, we can

    replace the -". and -"1 as LED and LED; "# doing

    this, we can easil# remember and the I3* port we are

    using

    @de!ine LCD7E -"

    @de!ine LCD7-S -"4

    @de!ine LCD D)&) (*-&D

    "esides that, user are not reBuired again to de!ine

    the LCD pin !or SK40C 6ser onl# reBuired to include

    the s#stemh !ile urther detail on LCD please re!er

    to (roject7;

    @de!ine &8 -C.

    @de!ine-8 -C1

    6ser are not reBuired again to de!ine the serial

    comunication /6)-& pin !or SK40C 6ser onl#

    reBuired to include the s#stemh !ile urther detail

    on 6)-& please re!er to (roject7

    2oid dela#7ms/unsigned intui72alueF

    unction protot#pe is the declaration o! a !unction

    that omits the !unction bod# but does speci!# the

    !unctionGs name, arit#, argument t#pes and return

    t#pe &he s#mbol 9 F : should put at the end o! thisline

    MAIN PROGRAM

    2oidmain /2oid

    In !igure abo2e is the main program stwe ha2e to

    t#pe 92oid main/2oid: at the st line to tell the

    micro%controller that this is the starting point o! the

    program

    $ere, 2oidmain, tell the compiler the name o! the

    !unctin which is main and it donGt return an#

    data/2oid

    (*-&) H 0F

    Clear the (*-& to pre2ent !rom the data latch on the

    (IC 'C6

    &-IS) H0b00000000F

    is the &ri%S&)&E -egister that declare the I3* ports asan I+(6& or *6&(6& b# /HI+(6& and /0H*6&(6&

    Eg &-IS" H 0b0000 is to set the (*-&"1J4 to

    *6&(6& and (*-&J0 as I+(6&

    LED H 0F

    &hen, we make the LED o!! b# gi2ing it a 0at initial

    state as show abo2e So as the LED; too &o make it

    on, just change the 0to

  • 8/13/2019 P0 User Manual

    3/3

    while/

    &o make the program loop !ore2er, we use while/

    !unction whileconstruct consists o! a block o! code

    and a condition &he condition is e2aluated, and i!

    the condition is true, the code within the block is

    e=ecuted In here, we put / to indicated that the

    condition is true

    dela#7ms/00F

    is a !unction call is an e=pression containing a simple

    t#pe name and a parenthesied argument list &he

    argument list can contain an# number o! e=pression

    separated b# commas It can also be empt# In here,

    we put the arguments list as 00 which is 00ms

    Comment line //

    In the code, we can !ound the //on the right hand

    side o! the code &he //is simpl# a comment in the

    code and is ignore b# the compiler )n# code that

    behind the//is ignore b# compiler and is just simpl#

    there !or #ou, or e2er#one to reads the code

    Comments are essential in the code to help #ou to

    better understanding on what going on and how the

    code works Comments can be put a!ter the

    command as in the ne=t line o! the program

    *n the other hand, #ou can also put comments into

    the block statement b# using /*and */

    EgJ

    3 )ll the code within the slash and

    asterisks will be ignore b# compiler 3

    2oiddela#7ms/unsigned intui72alue

    is an !unction that will be call and per!orm in the

    main !unction 92oid dela#7ms:, here we are telling

    the compiler that out !unction is name dela#7ms and

    it donGt return an# data /2oid

    /unsigned intui72alue

    is the parameter use to insert 2alue depending to our

    reBuirement 9int: mean integer which the minimum

    allow range are between %;1.1 to M;1.1/; "#tes

    9unsigned int: mean that the data we can insert is

    between 0 to . &here are man#data t#pethatwe can assign and use that act as the temporar#

    space !or micro%controller to store the data

    while/ui72alue%% 0

    in this condition, i! the ui72alue is subtract b# one at

    the time and check i! the ui72alue isGt still greater

    then 0 &he code within the while loop will be

    running !or man# times until the ui72alue is less then

    0

    77dela#7ms/F

    &his is the macro !rom $I%&EC$ complier which will

    generate ms dela# base on 2alue o! 78&)L7-EA

    http://en.wikipedia.org/wiki/C_variable_types_and_declarationshttp://en.wikipedia.org/wiki/C_variable_types_and_declarationshttp://en.wikipedia.org/wiki/C_variable_types_and_declarationshttp://en.wikipedia.org/wiki/C_variable_types_and_declarations