View previous topic :: View next topic |
Author |
Message |
jake1272
Joined: 15 Mar 2021 Posts: 37
|
ibutton DS1990R [Solved] |
Posted: Fri Mar 19, 2021 5:53 am |
|
|
The compiler is CCS v5.015
The IDE is MPLAB X IDE v5.40
Hi everyone I am working on a simple project with ibutton
I Noted the value of the last byte printed in the terminal
and then I Placed that value in a variable in my program
I want to add a code to light a green LED if the last byte matches
the variable or a red LED if the last byte does not
match.
Here is my try. I can light the green led but not the red. Any suggestions?
Thanks
Code: |
#include <16F1847.h>
#fuses INTRC_IO,NOWDT,NOPROTECT,PUT,NOMCLR,NOBROWNOUT
#use delay(clock=8000000)
#use rs232(baud=9600,UART1,STREAM=PC)
#define TOUCH_PIN PIN_B0
#include <touch.c>
#define LED PIN_B4
#define LED PIN_B5
short touch_present();
unsigned char touch_read_byte();
unsigned char value;
void main(){
printf("\nReady to read...");
unsigned char buffer[8],i;
char value=0xD5;
port_b_pullups(0xFF);
while(1){
printf("\r\nWaiting for a touch device...\r\n");
while(!touch_present());
output_low(PIN_B4);
output_low(PIN_B5);
delay_ms(1000);
if(touch_present()){
touch_write_byte(0x33);
for(i=0;i<8;++i) buffer[i]=touch_read_byte();
printf("Family:%2X ID:",buffer[0]);
for(i=6;i!=0;--i)printf("%2X",buffer[i]);
printf("\r\n");
delay_ms(1000);
if(buffer[1]==value)
output_high(PIN_B5);
else output_high(PIN_B4);
delay_ms(1000);
}
}
} |
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Fri Mar 19, 2021 8:38 am |
|
|
here's one possible problem..
...
#define LED PIN_B4
#define LED PIN_B5
...
I assume you meant to define
#define RED_LED PIN_B4
#define GRN_LED PIN_B5
or maybe
#define GRN_LED PIN_B4
#define RED_LED PIN_B5
??
also for test purposes, you should print out the value of 'value' along with the Ibutton data. That way you can SEE the data. |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
Re: ibutton DS1990R |
Posted: Sat Mar 20, 2021 3:19 am |
|
|
jake1272 wrote: |
Code: |
#define LED PIN_B4
#define LED PIN_B5
|
|
Yea -- definitely having LED defined twice is a no-go. _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
jake1272
Joined: 15 Mar 2021 Posts: 37
|
|
Posted: Wed Mar 24, 2021 1:23 pm |
|
|
Thanks. It is working now |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Wed Mar 24, 2021 2:21 pm |
|
|
Excellent.
Make sure to go to the original message of your thread and edit the subject to include [SOLVED] so it shows up in the forum list as such for other readers.
_________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
|