![]() |
![]() |
![]() |
|
|
|||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
|
|
Thread Tools | Display Modes |
|
|
(permalink) |
|
Hey guys,
Has anyone successfully read the address of a DS1990a ibutton with a 16f series PIC microcontroller before? I've got the codes in assembly but I have to do it in C. My compiler is CCS 4.057 btw. Can anyone here help me with the codes? thanks in advance. |
|
|
|
|
|
|
(permalink) |
|
hey,
I got this from MELabs PICBASIC Compiler - UK Distributor, Worldwide shipping on how to read the address of an ibutton but I cannot seem to get it working. I have saved the library and invoked it using #include "lib1.h" but I keep getting 6 errors. the errors have something to do with BYTE, i and data not being valid identifiers. Can someone help me with the code and explain what does BYTE actually mean? btw big thanks to oscar from chile for providing this piece of code. #include void main() { BYTE buffer[8]; BYTE i; printf("\r\nWaiting for a touch device...\r\n"); while (TRUE) { while(!touch_present()) ; delay_ms(200); if(touch_present()) { touch_write_byte(0x33); for(i=0;i<8;++i) buffer[i]=touch_read_byte(); } } } //you need to use this lib /////////////////////////////////////////////////////////////////////////// //// Dallas Touch Driver //// //// //// //// present = touch_present() Issues a reset and returns TRUE //// //// if the touch device is there. //// //// //// //// data = touch_read_BYTE() Reads one BYTE from a touch device. //// //// //// //// ok = touch_write_BYTE(data) Writes one BYTE to a touch device //// //// and returns TRUE if all went OK. //// //// A FALSE indicates a collision with //// //// another device. //// //// //// /////////////////////////////////////////////////////////////////////////// //// Derivative programs created using this software in object code //// //// form are not restricted in any way. //// /////////////////////////////////////////////////////////////////////////// #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 BYTE touch_read_byte() { BYTE i,data; for(i=1;i<=8;++i) { output_low(TOUCH_PIN); delay_us(14); output_float(TOUCH_PIN); delay_us(5); shift_right(&data,1,input(TOUCH_PIN)); delay_us(100); } return(data); } BYTE touch_write_byte(BYTE data) { BYTE i; for(i=1;i<=8;++i) { output_low(TOUCH_PIN); delay_us(10); if(shift_right(&data,1,0)) { output_high(TOUCH_PIN); delay_us(10); if(!TOUCH_PIN_BIT) return(0); } else { output_low(TOUCH_PIN); delay_us(10); if(TOUCH_PIN_BIT) return(0); } delay_us(50); output_high(TOUCH_PIN); delay_us(50); } return(TRUE); } BYTE touch_present() { BOOLEAN present; output_low(TOUCH_PIN); delay_us(500); output_float(TOUCH_PIN); delay_us(5); if(!input(TOUCH_PIN)) return(FALSE); delay_us(65); present=!input(TOUCH_PIN); delay_us(240); if(present) return(TRUE); else return(FALSE); } |
|
|
|
|
|
|
(permalink) |
|
Probably your compiler doesn't accept 'BYTE' as a type qualifier. Try replacing 'BYTE' with 'unsigned char'.
|
|
|
|
|
|
|
(permalink) |
|
Try changing BYTE to char or unsigned char.
Mike. |
|
|
|
|
|
|
(permalink) |
|
Will try it. Thanks guys.
|
|
|
|
|
|
|
(permalink) |
|
One more thing, since the PIC has no form of graphical output, what does this line actually do? printf("\r\nWaiting for a touch device...\r\n");
|
|
|
|
|
|
|
(permalink) |
|
|
|
|
|
|
|
|
(permalink) |
|
Just a heads up for the OP, you will get a lot more in depth response on compiler specific questions on the PDS Forums, not that it really matters, just a heads up
__________________
Spency. PIC Micro's - Your mind is the limit PIC's and interfacing with other devices - a PIC Basic Guide @ digital-diy.net |
|
|
|
|
|
|
(permalink) |
|
guys, i've tried to change BYTE to unsigned char and char but i still get the same errors.
here's what it says; *** Error 51 "test1a.c" Line 21(1,9): A numeric expression must appear here *** Error 51 "test1a.c" Line 22(1,4): A numeric expression must appear here *** Error 12 "test1a.c" Line 30(5,6): Undefined identifier i *** Error 12 "test1a.c" Line 30(9,10): Undefined identifier i *** Error 12 "test1a.c" Line 30(15,16): Undefined identifier i 5 Errors, 1 Warnings. bah i'm wits end!!! |
|
|
|
|
|
|
(permalink) |
|
Can you post the code. Put [code] before the code and [/code] after it to preserve the formating. It would help if you identified the error lines.
Mike. |
|
|
|
|
|
|
(permalink) |
|
I've got it. I made a fundamental mistake declaring the variables within the while(1) loop.
I've changed it and the thing builds fine. Now i want to check whether the PIC has successfully read the ibutton. Any ideas? I've used the read function in MPLAB to read the contents of the PIC but apparently all the registers are still zero. something is not right hmmm here's the code btw Code:
#include <16F628.h>
#include <stdio.h>
#use fixed_io(b_outputs=PIN_B4)
#use delay(xtal = 4000000)
#include "lib2.h"
void main()
{
BYTE buffer[8];
BYTE i;
while(1){
output_high(PIN_B4);
delay_ms(500);
output_low(PIN_B4);
delay_ms(500);
//printf("\r\nWaiting for a touch device...\r\n");
while(!touch_present()) ;
delay_ms(200);
if(touch_present()) {
touch_write_byte(0x33);
for(i=0;i<8;++i)
buffer[i]=touch_read_byte();
}
}
}
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
BYTE touch_read_byte() {
BYTE i,data;
for(i=1;i<=8;++i) {
output_low(TOUCH_PIN);
delay_us(14);
output_float(TOUCH_PIN);
delay_us(5);
shift_right(&data,1,input(TOUCH_PIN));
delay_us(100);
}
return(data);
}
BYTE touch_write_byte(BYTE data) {
BYTE i;
for(i=1;i<=8;++i) {
output_low(TOUCH_PIN);
delay_us(10);
if(shift_right(&data,1,0)) {
output_high(TOUCH_PIN);
delay_us(10);
if(!TOUCH_PIN_BIT)
return(0);
} else {
output_low(TOUCH_PIN);
delay_us(10);
if(TOUCH_PIN_BIT)
return(0);
}
delay_us(50);
output_high(TOUCH_PIN);
delay_us(50);
}
return(TRUE);
}
BYTE touch_present() {
BOOLEAN present;
output_low(TOUCH_PIN);
delay_us(500);
output_float(TOUCH_PIN);
delay_us(5);
if(!input(TOUCH_PIN))
return(FALSE);
delay_us(65);
present=!input(TOUCH_PIN);
delay_us(240);
if(present)
return(TRUE);
else
return(FALSE);
}
Last edited by konzen; 23rd May 2008 at 08:17 AM. |
|
|
|
|
|
|
(permalink) |
|
You could write it into EEPROM and read it that way.
Code:
if(touch_present()) {
touch_write_byte(0x33);
for(i=0;i<8;++i){
buffer[i]=touch_read_byte();
write_eeprom(i,buffer[i]);
}
}
Mike. |
|
|
|
|
|
|
(permalink) |
|
I think the DS1990A does not have EEPROM. it's an ID only ibutton. I've tried using an osciloscope to read the voltage levels that the input pin is seeing (pin b0) but everytime i touch the ibutton to the to reader, all i get is minor fluctuations in the mV region.
besides that, I've also entered codes to turn off an led everytime the ibutton is touched, Code:
while(!touch_present()) ;
output_high(PIN_B4); // while ibutton not touched....turn on LED
delay_ms(200);
if(touch_present()) {
output_low(PIN_B4); // when ibutton touched... turn it off
thanks |
|
|
|
|
|
|
(permalink) |
|
write_eeprom writes to the EEPROM in the pic. You can then read the EEPROM with your programmer to see the ID.
Can you post more of your LED code. Mike. |
|
|
|
|
|
|
(permalink) |
|
I see. perhaps i'm running incompatible code on my computer? My compiler is CCS 4.057 but I do not know what compiler that code is based on.
Code:
#include <16F628.h>
#include <stdio.h>
#use fixed_io(b_outputs=PIN_B4)
#use delay(xtal = 4000000)
#include "lib2.h"
#use rs232(baud = 9600, xmit=PIN_B2, rcv=PIN_B1, stop=1,)
void main()
{
BYTE buffer[8];
BYTE i;
while(TRUE){
//printf("\r\nWaiting for a touch device...\r\n");
while(!touch_present()) ;
output_high(PIN_B4);
delay_ms(200);
if(touch_present()) {
output_low(PIN_B4);
touch_write_byte(0x33);
for(i=0;i<8;++i)
buffer[i]=touch_read_byte();
}
for(i=0; i<8; i++)
putc(buffer[i]);
}
}
oh yeah btw sometimes my LED does get turned on indicating that the program has stepped into the while(!touch_present) area. sometimes it doesn't. btw how do i use the read function on my compiler to read the eeprom? |
|
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
|
|
||||
| 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 |