CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Please can anyone convert this code into C code ( ccs c) ?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
WAQASKHAN



Joined: 26 Apr 2012
Posts: 4

View user's profile Send private message

Please can anyone convert this code into C code ( ccs c) ?
PostPosted: Thu Apr 26, 2012 8:39 am     Reply with quote

Code:

//Project: Buzzer and PIR Lesson
//Programmer: Shahrulnizam Mat Rejab
//PIC: PIC16F877A, PIC16F887
//Crystal Frequency: 20MHz
//Compiler: HI-TECH ANSI C V9.83
//Last Modified: 19 March 2012
//Website: http://shahrulnizam.com

#include <htc.h>
#include "LibraryPIC40pin.h"
#if defined (_16F877A)
   __CONFIG(FOSC_HS & WDTE_OFF & PWRTE_ON & BOREN_OFF & LVP_OFF);
#elif defined (_16F887)
   __CONFIG(FOSC_HS & WDTE_OFF & PWRTE_ON & BOREN_OFF & MCLRE_ON &   LVP_OFF);
#endif

#define PIR      RB0
#define BUZZER      RB1

void pic_init();

main()
{
pic_init();               //initialize PIC
for(;;){               //loop forever
   BUZZER=PIR;}
}

void pic_init()
{
TRISA=0b00000000;
TRISB=0b00000001;
TRISC=0b00000000;
TRISD=0b00000000;
TRISE=0b00000000;
#if defined (_16F877A)
   ADCON0=0b00000110;
#elif defined (_16F887)
   ANSEL=0b00000000;
   ANSELH=0b00000000;   
#endif         
PORTA=0b00000000;
PORTB=0b00000000;
PORTC=0b00000000;
PORTD=0b00000000;
PORTE=0b00000000;
}
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Thu Apr 26, 2012 9:20 am     Reply with quote

Hi,

That program looks trivial, and most of it would go when re-written in CCS 'C'.

It would help if we knew what the program was supposed to do? It looks like you simply want to sound a buzzer whenever a PIR (passive infrared sensor) detects motion? Is that correct?

John
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Fri Apr 27, 2012 3:47 am     Reply with quote

Sorry, but this is almost too easy.
I don't mind to help you, but if you don't learn the basic knowledge then you will never be able to program by yourself.

The program you posted is a bit difficult to start with because there is a lot of initialization code for the hardware that is different for each compiler. The easiest way to solve that is by throwing that part away and start from scratch. Start the CCS compiler and use the Project Wizard to start a new project. This will guide you through all possible options for setting up the hardware and gives you a good project start.

The next part will be to convert the main part of the original program to your new project. Surprise! This is only 4 lines of code! I'm sure you can do that yourself. Cool
When you do get stuck, then post the code as far you have it and we will help you further.
WAQASKHAN



Joined: 26 Apr 2012
Posts: 4

View user's profile Send private message

PostPosted: Fri Apr 27, 2012 9:09 am     Reply with quote

PLEASE HELP ME CAN ANY ONE SIMPLT CONVERT THE LOGIC OF THE PROGRAMME IN TO C LANGUAGE ? PLEASEEE
Ttelmah



Joined: 11 Mar 2010
Posts: 19358

View user's profile Send private message

PostPosted: Fri Apr 27, 2012 9:19 am     Reply with quote

This is not a 'write code for you' forum.
In CCS, this could be done in about 10 lines, but nobody is going to do this for you. Try yourself, and post what doesn't work, then we may _help_. Ckielstra's answer is the only one you are going to get, especially if you SHOUT.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group