A Microcontroller Discussion Board
September 07, 2010, 03:09:18 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: You may have to register before you can post: click the register link below to proceed.
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Why program the PIC18 in C  (Read 1437 times)
0 Members and 1 Guest are viewing this topic.
king_diaw
Freshy
*
Posts: 11


View Profile
« on: April 08, 2008, 05:11:12 AM »

four major reasons:
1) less time consuming.
2) easier to modify and update
3) can use code available in function library
4) Portable to other microcontroller with litter or no modification

some body that interest want to program the PIC in C, I'm suggest you to use C18 complier with integrated to MPLAB IDE
« Last Edit: August 28, 2008, 02:13:51 AM by king_diaw » Logged
A Microcontroller Discussion Board
« on: April 08, 2008, 05:11:12 AM »

 Logged
AzkA
Freshy
*
Posts: 6


View Profile Email
« Reply #1 on: January 17, 2009, 04:21:37 AM »

yes.. that the reason why use C in PIC.. but that still have the limition.. the prgram that compile from C is more big.. then it need more space memory in PIC
Logged
king_diaw
Freshy
*
Posts: 11


View Profile
« Reply #2 on: January 18, 2009, 06:03:30 AM »

thanks for your answer.
now I'm doing some project that using I2C interfacing. PIC18F4550 as master and PIC182550 as slave.
I actually can't communicate those IC's yet. Do you know how to use i2c.h library to configure PIC18F2550 as a slave?

for the master configuration I'm already done. The sample code for the master configuration as shown below.

Code:
void i2c_start(unsigned char address, unsigned char size, unsigned operation)
{
unsigned char i;

SSPCON2bits.SEN = 1; //send START
while(!SSPIF); //hold program until progress is completed (SSPIF will be set)
SSPIF = 0; //clear flagbit caused by START
SSPBUF = address + operation; //send addres to slave (operation = 1 if read, 0 if write)
while(!SSPIF); //hold program until data is transmitted (SSPIF will be set if completed)
SSPIF = 0; //clear flagbit caused by transmission
if(operation == write) //if write operaion
{
for(i = 0; i < size; i++)
{
SSPBUF = i2c_master_data[i]; //send data[i]
while(!SSPIF); //hold program until transmission is completed
SSPIF = 0; //clear flagbit caused by transmission
}
SSPCON2bits.PEN = 1; //after all data is transmitted, send STOP
while(!SSPIF); //hold program until progress is completed (SSPIF will be set)
SSPIF = 0; //clear flagbit caused by STOP
}
else if(operation == read) //else read operation
{
for(i = 0; i < size; i++)
{
SSPCON2bits.RCEN = 1; //enable reception
while(!SSPIF); //hold program until progress is completed (SSPIF will be set)
SSPIF = 0; //clear flagbit caused by reception
i2c_master_rcvb[i] = SSPBUF; //store data in rcvb[i]
if(i == (size - 1)) //if last byte, send NACK
SSPCON2bits.ACKDT = 1; //successful transfer data
else //else send ACK
SSPCON2bits.ACKDT = 0;
SSPCON2bits.ACKEN = 1; //send acknowledgement
while(!SSPIF); //hold program until progress is completed (SSPIF will be set)
SSPIF = 0; //clear flagbit caused by acknowledgement
}
SSPCON2bits.PEN = 1; //after all data is transmitted, send STOP
while(!SSPIF); //hold program until progress is completed (SSPIF will be set)
SSPIF = 0; //clear flagbit caused by STOP
}
}
Logged
A Microcontroller Discussion Board
   

 Logged
Pages: [1]
  Print  
 
Jump to:  

Related Topics
Subject Started by Replies Views Last post
How to burn a program into PIC 16F84 PIC xylynn 3 1326 Last post May 25, 2008, 11:14:46 AM
by AzkA
check my program >>>!! 8051 flashking 0 999 Last post January 16, 2008, 02:02:10 AM
by flashking
Program to multiple two numbers PIC king_diaw 0 487 Last post April 10, 2008, 08:54:06 AM
by king_diaw
How make the burner to burn PIC program's PIC AzkA 4 1213 Last post February 04, 2009, 10:31:59 PM
by gogo2520
program Announcements krishnaa 0 391 Last post February 09, 2010, 01:23:08 PM
by krishnaa
Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC | Sitemap Valid XHTML 1.0! Valid CSS!