Searching \ for '[PIC]:PIC C source code' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/languages.htm?key=c
Search entire site for: 'PIC C source code'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]:PIC C source code'
2004\03\16@205542 by Nicholas

picon face
Can someone advise me whether is my source code is correct? I am doing a security warning system for my project and writing the program in PIC C. The PIR sensor will sense for movement and the PIC18F452 Microcontroller will get the data from the EEPROM and send it to the DAC using the I2C bus. Both devices are I2C devices. Here is my source code. I am using the MPLAB C18 complier to write the code. Please advise me.

Component I'm using:
Microcontroller : PIC18F452
EEPROM : Microchip 24LC256
DAC : MAX517

#include<p18f452.h>
#include<i2c.h>

//function prototype
void MAX517(unsigned int channel);

void main(void){
   char err, data_to_DAC, I2C_err;
   unsigned char *rdptr;
   int i;

   //init condition
   TRISB = 0X10; //Set PORTB Bit 4 as Input, the rest as output
   TRISC = 0X1A; //Set SDA & SCL as 1. Activate I2C port
       OpenI2C(MASTER, SLEW_ON); //Initialize I2C module
   SSPADD = 9; //400KHz Baud clock (9) @16MHz
       while(1){ //Start condition
       if(PORTBbits.RB4 == 1){ //detect movement
           err = EESequentialRead(0xA1, 0x00, rdptr, 1); //make current address at 0xA1
                               for(i=0; i<4096; i++){ //8Kbyte per wave x 1024 x 4 waves
                   data_to_DAC = EECurrentAddRead(0xA1); //Read a single byte EEPROM and store in temp
                   I2C_err = EEAckPolling(0xA10); //Send Ack to PIC
                   MAX517(data_to_DAC); //Write data to I2C DAC
                   }//end for             }//end if
   }//end while
}//end main

void MAX517(unsigned int channel){
   StartI2C(); //Start condition
   WriteI2C(0x58); //Address byte of DAC
   AckI2C(); //Ack
   WriteI2C(0x00); //Command byte
   AckI2C(); //Ack
   WriteI2C(channel); //Output Data
   AckI2C(); //Ack
   StopI2C(); //Stop condition
}//end of MAX517 funtion

--
http://www.piclist.com hint: To leave the PICList
spam_OUTpiclist-unsubscribe-requestTakeThisOuTspammitvma.mit.edu

2004\03\16@220307 by Ken Pergola

flavicon
face
Nicholas wrote:

> Can someone advise me whether is my source code is correct?

Hi Nicholas,

I'd like to try to help you, but could you provide some more details?
I could not tell from your post if your project is working or not.

Do you mean 'correct' in terms of 'best practices' of C coding or do you
mean 'correct' in terms of the program is not compiling correctly, or
'correct' in terms of your microcontroller (programmed with your code) is
not working as you intended.

If you can be more specific you'll probably have a better chance of someone
helping you out.

1) Does your C program compile without error(s)?
2) Does it work partially or not at all as you expect?
3) Have you tested your I2C routines to see if they work with your I2C
devices?

Come on back with some more details and I'm sure someone will help you get
back on track if you are having problems.

Best regards,

Ken Pergola

--
http://www.piclist.com hint: To leave the PICList
.....piclist-unsubscribe-requestKILLspamspam@spam@mitvma.mit.edu

More... (looser matching)
- Last day of these posts
- In 2004 , 2005 only
- Today
- New search...