Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 24th May 2008, 03:44 AM   (permalink)
Default

oh one more thing, when i declare variables as byte, it doesn't turn blue the way int, for, if and while turns blue. i'm starting to believe that byte is not the correct choice of variable type. perhaps i'll try unsigned char.
konzen is offline  
Reply With Quote
Old 24th May 2008, 05:20 AM   (permalink)
Default

Do you realise that your code is waiting until the button is missing?

I indented and commented your code,
Code:
void main()
{
BYTE buffer[8];
BYTE i;
    while(TRUE){
        //printf("\r\nWaiting for a touch device...\r\n");

        while(!touch_present());	//wait for button to be missing
        output_high(PIN_B4);		//light LED
        delay_ms(200);			

        if(touch_present()) {		//if button is present
            output_low(PIN_B4);		//extinguish LED
            touch_write_byte(0x33);	//write command ReadRom
            for(i=0;i<8;++i)		//read the 8 byte ID
            	buffer[i]=touch_read_byte();
        }
        for(i=0; i<8; i++)
           putc(buffer[i]);

    }
}
The write_eeprom routine I used above is for the CCS compiler. I found it on page 243 of this document.

Mike.

Last edited by Pommie; 24th May 2008 at 05:22 AM.
Pommie is offline  
Reply With Quote
Old 24th May 2008, 05:23 AM   (permalink)
Default

Try putting BYTE in lower case.

Mike.
Pommie is offline  
Reply With Quote
Old 26th May 2008, 08:44 AM   (permalink)
Default

Really?

Isn't that line saying 'as long as the ibutton is missing?'

Code:
void main()
{
BYTE buffer[8];
BYTE i;
    while(TRUE){
        //printf("\r\nWaiting for a touch device...\r\n");

        while(!touch_present());	//wait for button to be missing...'as long as ibutton is     
                                                   missing'
        output_high(PIN_B4);		//light LED
        delay_ms(200);			

        if(touch_present()) {		//if button is present
            output_low(PIN_B4);		//extinguish LED
            touch_write_byte(0x33);	//write command ReadRom
            for(i=0;i<8;++i)		//read the 8 byte ID
            	buffer[i]=touch_read_byte();
        }
        for(i=0; i<8; i++)
           putc(buffer[i]);

    }
}
konzen is offline  
Reply With Quote
Old 26th May 2008, 09:21 AM   (permalink)
Default

Quote:
Originally Posted by konzen View Post
Really?

Isn't that line saying 'as long as the ibutton is missing?'
Yes, my mistake. I must have been asleep when I wrote that. Have you got it working now?

Mike.
Pommie is offline  
Reply With Quote
Old 26th May 2008, 10:04 AM   (permalink)
Default

haha lol,

So far when I touch the ibutton to the reader, fluctuations between 5V and 0 V were observed. This is rather good news. However, my MAX232 circuit is having a couple of problems so I can't transmit via RS232 to the PC.

I've tried the read function on the compiler to read the contents of the PIC but to no avail.

Any ideas?

in the meantime I'll be working on the MAX232 circuit
konzen is offline  
Reply With Quote
Old 26th May 2008, 10:43 AM   (permalink)
Default

A good way to test if your MAX232 circuit is working is to remove the pic from it's socket and connect the RX and TX pins (7 & 8) together. If you then run Hyperterminal and select flow control = none, you should see what you type echoed back.

As for storing the ID in the EEPROM, you should be able to read the EEPROM with your programmer. What programmer are you using?

Mike.
Pommie is offline  
Reply With Quote
Old 26th May 2008, 10:49 AM   (permalink)
Default

I see. Will try it. I'm using MPLAB IDE v7.60 which is readily available on the terminal I'm working on in uni.
konzen is offline  
Reply With Quote
Old 26th May 2008, 05:16 PM   (permalink)
Default

I've tested my max232 circuit and its working fine. tried with the ibutton in place but nothing happens. I've tried just sending fixed hex values from the PIC but still nothing works.

example : putc(0x11)

I've defined #use RS232 in the header and all the relevant options such as baudrate, xmit and and rcv pin.

Will continue tmrw
konzen is offline  
Reply With Quote
Old 28th May 2008, 09:24 AM   (permalink)
Default

Hey,

new update:
the max232 circuit works good. I can send values from the PIC to the PC with no problems now. however, I still can't get the PIC to read the ibutton.

the PIC always seems to loop in the wait state. No matter what I tried, I can't get it to respond to an ibutton touch.

I suspect that I did not define whether the pin i'm using to serve as an output or input that's being the cause to this.

however, since the bus is 1-wire, the pin is required to serve as both input and output. how do i do this?

btw i've also found out that byte and boolean are predefined variable types in the PIC header file so even though they don't turn blue when I type them there is nothing wrong.

And can you explain this area of code to me?

Code:
#ifndef TOUCH_PIN
#define TOUCH_PIN PIN_B0
#if defined(__PCH__)
#bit TOUCH_PIN_BIT = 0xF8A.0
#else
#bit TOUCH_PIN_BIT = 6.0
#endif
#endif
Thanks a bunch
konzen is offline  
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Latest
interfacing ibutton to PC using USB konzen General Electronics Chat 26 13th May 2008 10:31 AM
8051 microcontroller reading data from serial port godatguitar Micro Controllers 11 17th February 2004 08:03 PM
Specifications Applied Caltech General Electronics Chat 1 25th December 2003 05:00 PM



All times are GMT. The time now is 11:44 PM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.