View previous topic :: View next topic |
Author |
Message |
WAQASKHAN
Joined: 26 Apr 2012 Posts: 4
|
Please can anyone convert this code into C code ( ccs c) ? |
Posted: Thu Apr 26, 2012 8:39 am |
|
|
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
|
|
Posted: Thu Apr 26, 2012 9:20 am |
|
|
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
|
|
Posted: Fri Apr 27, 2012 3:47 am |
|
|
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.
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
|
|
Posted: Fri Apr 27, 2012 9:09 am |
|
|
PLEASE HELP ME CAN ANY ONE SIMPLT CONVERT THE LOGIC OF THE PROGRAMME IN TO C LANGUAGE ? PLEASEEE |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Fri Apr 27, 2012 9:19 am |
|
|
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. |
|
|
|