CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

ibutton DS1990R [Solved]

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
jake1272



Joined: 15 Mar 2021
Posts: 37

View user's profile Send private message

ibutton DS1990R [Solved]
PostPosted: Fri Mar 19, 2021 5:53 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Mar 19, 2021 8:38 am     Reply with quote

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

View user's profile Send private message

Re: ibutton DS1990R
PostPosted: Sat Mar 20, 2021 3:19 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Mar 24, 2021 1:23 pm     Reply with quote

Thanks. It is working now Very Happy
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Wed Mar 24, 2021 2:21 pm     Reply with quote

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.

Smile
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group