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

12F1822 IR Remote Receiver
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Denny9167



Joined: 15 Feb 2021
Posts: 49

View user's profile Send private message Send e-mail

12F1822 IR Remote Receiver
PostPosted: Thu Mar 11, 2021 6:52 pm     Reply with quote

Since there was a post regarding problems with the IR transmitter using the 12F1822 and NEC protocol, I thought I would post the Rx code. I compiled it (build successful!) and programmed the hex code to the PIC, and the PIC is unresponsive. I’m using a certified NEC remote for testing, I believe the numbers (1 thru 5) are used to drive each LED, BTW My compiler is v5.103. A couple of things I noticed about the code is only the input pin is defined, and the outputs aren’t? Maybe I’m missing something.

All connections made per schematic, I even tested the IR receiver with an LED connected to it, and it seems to be fine.
Code:


// Extended NEC protocol IR remote control decoder using PIC12F1822 CCS PIC C code
// http://ccspicc.blogspot.com/
// [email protected]
// Use at your own risk

#include <12F1822.h>
#fuses NOMCLR INTRC_IO PLL_SW
#use delay(clock=32000000)
#use fast_io(A)
#define IR_Sensor PIN_A3

unsigned int32 ir_code;
short nec_remote_read(){
  unsigned int16 count = 0;
  unsigned int8 i;
  // Check 9ms pulse (remote control sends logic high)
  SET_TIMER1(0);
  while(!input(IR_Sensor) && (count < 9500))
    count = GET_TIMER1();
  if( (count > 9499) || (count < 8500))
    return FALSE;
  // Check 4.5ms space (remote control sends logic low)
  SET_TIMER1(0);
  count = 0;
  while((input(IR_Sensor)) && (count < 5000))
    count = GET_TIMER1();
  if( (count > 4999) || (count < 4000))
    return FALSE;
  // Read message (32 bits)
  for(i = 0; i < 32; i++){
    SET_TIMER1(0);
    count = 0;
    while(!input(IR_Sensor) && (count < 650))
      count = GET_TIMER1();
    if( (count > 649) || (count < 500))
      return FALSE;
    count = 0;
    SET_TIMER1(0);
    while((input(IR_Sensor)) && (count < 1800))
      count = GET_TIMER1();
    if( (count > 1799) || (count < 400))
      return FALSE;
    if( count > 1000)                                 // If space width > 1ms
      bit_set(ir_code, (31 - i));                     // Write 1 to bit (31 - i)
    else                                              // If space width < 1ms
      bit_clear(ir_code, (31 - i));                   // Write 0 to bit (31 - i)
  }
  return TRUE;
}
void main() {
  setup_oscillator(OSC_8MHZ | OSC_PLL_ON);            // Set internal oscillator to 32MHz (8MHz and PLL)
  output_a(0);
  set_tris_a(8);
  SETUP_TIMER_1(T1_INTERNAL | T1_DIV_BY_8);
  while(TRUE){
    while(input(IR_Sensor));                          // Wait until IR_Sensor pin falls
    if(nec_remote_read()){
      if(ir_code == 0x40BF00FF)
        output_toggle(PIN_A0);
      if(ir_code == 0x40BF807F)
        output_toggle(PIN_A1);
      if(ir_code == 0x40BF40BF)
        output_toggle(PIN_A2);
      if(ir_code == 0x40BF20DF)
        output_toggle(PIN_A4);
      if(ir_code == 0x40BFA05F)
        output_toggle(PIN_A5);
      }
  }
}

temtronic



Joined: 01 Jul 2010
Posts: 9241
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Mar 11, 2021 7:24 pm     Reply with quote

Not 'defined' but used....
ie:
Quote:
if(ir_code == 0x40BF00FF)
output_toggle(PIN_A0);
if(ir_code == 0x40BF807F)
output_toggle(PIN_A1);
if(ir_code == 0x40BF40BF)
output_toggle(PIN_A2);
if(ir_code == 0x40BF20DF)
output_toggle(PIN_A4);
if(ir_code == 0x40BFA05F)
output_toggle(PIN_A5);

Kinda 'sloppy' programming as the output pins should have been '#defined' in the beginning, though maybe the OPgmr didn't know which pin was which 'button pressed' ? Perhaps a 'work in progress' ?
Denny9167



Joined: 15 Feb 2021
Posts: 49

View user's profile Send private message Send e-mail

PostPosted: Thu Mar 11, 2021 7:47 pm     Reply with quote

temtronic wrote:
Not 'defined' but used....
ie:
if(ir_code == 0x40BF00FF)
output_toggle(PIN_A0);
if(ir_code == 0x40BF807F)
output_toggle(PIN_A1);
if(ir_code == 0x40BF40BF)
output_toggle(PIN_A2);
if(ir_code == 0x40BF20DF)
output_toggle(PIN_A4);
if(ir_code == 0x40BFA05F)
output_toggle(PIN_A5);

kinda 'sloppy' programming as the output pins should have been '#defined' in the beginning,though maybe the OPgmr didn't know which pin was which 'button pressed' ? Perhaps a 'work in progress' ?


Thanks, this was posted on a blog site.
Denny9167



Joined: 15 Feb 2021
Posts: 49

View user's profile Send private message Send e-mail

PostPosted: Thu Mar 11, 2021 7:48 pm     Reply with quote

This is what I came up with will try it later.

Code:

// Extended NEC protocol IR remote control decoder using PIC12F1822 CCS PIC C code
// http://ccspicc.blogspot.com/
// [email protected]
// Use at your own risk

#include <12F1822.h>
#fuses NOMCLR INTRC_IO PLL_SW
#use delay(clock=32000000)
#use fixed_IO( A_outputs=PIN_A5,PIN_A4,PIN_A2,PIN_A1,PIN_A0 )
#define IR_Sensor   PIN_A3


unsigned int32 ir_code;
short nec_remote_read(){
  unsigned int16 count = 0;
  unsigned int8 i;
  // Check 9ms pulse (remote control sends logic high)
  SET_TIMER1(0);
  while(!input(IR_Sensor) && (count < 9500))
    count = GET_TIMER1();
  if( (count > 9499) || (count < 8500))
    return FALSE;
  // Check 4.5ms space (remote control sends logic low)
  SET_TIMER1(0);
  count = 0;
  while((input(IR_Sensor)) && (count < 5000))
    count = GET_TIMER1();
  if( (count > 4999) || (count < 4000))
    return FALSE;
  // Read message (32 bits)
  for(i = 0; i < 32; i++){
    SET_TIMER1(0);
    count = 0;
    while(!input(IR_Sensor) && (count < 650))
      count = GET_TIMER1();
    if( (count > 649) || (count < 500))
      return FALSE;
    count = 0;
    SET_TIMER1(0);
    while((input(IR_Sensor)) && (count < 1800))
      count = GET_TIMER1();
    if( (count > 1799) || (count < 400))
      return FALSE;
    if( count > 1000)                                 // If space width > 1ms
      bit_set(ir_code, (31 - i));                     // Write 1 to bit (31 - i)
    else                                              // If space width < 1ms
      bit_clear(ir_code, (31 - i));                   // Write 0 to bit (31 - i)
  }
  return TRUE;
}
void main() {
  setup_oscillator(OSC_8MHZ | OSC_PLL_ON);            // Set internal oscillator to 32MHz (8MHz and PLL)
  SETUP_TIMER_1(T1_INTERNAL | T1_DIV_BY_8);
  while(TRUE){
    while(input(IR_Sensor));                          // Wait until IR_Sensor pin falls
    if(nec_remote_read()){
      if(ir_code == 0x40BF00FF)
        output_toggle(PIN_A0);
      if(ir_code == 0x40BF807F)
        output_toggle(PIN_A1);
      if(ir_code == 0x40BF40BF)
        output_toggle(PIN_A2);
      if(ir_code == 0x40BF20DF)
        output_toggle(PIN_A4);
      if(ir_code == 0x40BFA05F)
        output_toggle(PIN_A5);
      }
  }
}

Denny9167



Joined: 15 Feb 2021
Posts: 49

View user's profile Send private message Send e-mail

PostPosted: Fri Mar 12, 2021 8:07 am     Reply with quote

I rebuilt the updated source file, it’s still unresponsive to remote commands
But three of the LED’s immediately went high on power up.
I’m thinking TIMER1 isn’t setting up properly?
Denny9167



Joined: 15 Feb 2021
Posts: 49

View user's profile Send private message Send e-mail

PostPosted: Sat Mar 13, 2021 3:58 pm     Reply with quote

I noticed this in the code:

[code]

set_tris_a(8);

[code/]

Shouldn’t this be “ set_tris_a(0x8);” for this chip?
Denny9167



Joined: 15 Feb 2021
Posts: 49

View user's profile Send private message Send e-mail

PostPosted: Sat Mar 13, 2021 4:20 pm     Reply with quote

Here is the List file for the compilation. it looks like a C to ASM conversion. I'm trying to learn ASM as well so Ill leave it to experts to point out any errors.

Thanks

CCS PCM C Compiler, Version 5.103, xxxxx 13-Mar-21 16:12

Filename: C:\Users\brown\OneDrive\Documents\CCS C Projects\RXNEC2.lst

ROM used: 430 words (21%)
Largest free fragment is 1618
RAM used: 9 (7%) at main() level
25 (20%) worst case
Stack used: 0 locations
Stack size: 16

*
0000: MOVLP 00
0001: GOTO 12F
0002: NOP
....................
....................
....................
....................
....................
....................
.................... // Extended NEC protocol IR remote control decoder using PIC12F1822 CCS PIC C code
.................... // http://ccspicc.blogspot.com/
.................... // [email protected]
.................... // Use at your own risk
....................
.................... #include <12F1822.h>
.................... //////////// Standard Header file for the PIC12F1822 device ////////////////
.................... ///////////////////////////////////////////////////////////////////////////
.................... //// (C) Copyright 1996, 2020 Custom Computer Services ////
.................... //// This source code may only be used by licensed users of the CCS C ////
.................... //// compiler. This source code may only be distributed to other ////
.................... //// licensed users of the CCS C compiler. No other use, reproduction ////
.................... //// or distribution is permitted without written permission. ////
.................... //// Derivative programs created using this software in object code ////
.................... //// form are not restricted in any way. ////
.................... ///////////////////////////////////////////////////////////////////////////
.................... #device PIC12F1822
....................
.................... #list
....................
.................... #fuses NOMCLR INTRC_IO
.................... #use delay(clock=8000000)
.................... #use fast_io(A)
.................... #define IR_Sensor PIN_A3
....................
.................... unsigned int32 ir_code;
.................... short nec_remote_read(){
0003: CLRF 25
0004: CLRF 24
.................... unsigned int16 count = 0;
.................... unsigned int8 i;
.................... // Check 9ms pulse (remote control sends logic high)
.................... SET_TIMER1(0);
0005: CLRF 16
0006: CLRF 17
0007: CLRF 16
0008: NOP
.................... while(!input(IR_Sensor) && (count < 9500))
0009: BTFSC 0C.3
000A: GOTO 022
000B: MOVF 25,W
000C: SUBLW 25
000D: BTFSS 03.0
000E: GOTO 022
000F: BTFSS 03.2
0010: GOTO 015
0011: MOVF 24,W
0012: SUBLW 1B
0013: BTFSS 03.0
0014: GOTO 022
.................... count = GET_TIMER1();
0015: MOVF 17,W
0016: MOVWF 7A
0017: MOVF 16,W
0018: MOVWF 77
0019: MOVF 17,W
001A: SUBWF 7A,W
001B: BTFSS 03.2
001C: GOTO 015
001D: MOVF 77,W
001E: MOVWF 24
001F: MOVF 7A,W
0020: MOVWF 25
0021: GOTO 009
.................... if( (count > 9499) || (count < 8500))
0022: MOVF 25,W
0023: SUBLW 24
0024: BTFSC 03.0
0025: GOTO 02D
0026: XORLW FF
0027: BTFSS 03.2
0028: GOTO 037
0029: MOVF 24,W
002A: SUBLW 1B
002B: BTFSS 03.0
002C: GOTO 037
002D: MOVF 25,W
002E: SUBLW 21
002F: BTFSS 03.0
0030: GOTO 03A
0031: BTFSS 03.2
0032: GOTO 037
0033: MOVF 24,W
0034: SUBLW 33
0035: BTFSS 03.0
0036: GOTO 03A
.................... return FALSE;
0037: MOVLW 00
0038: MOVWF 78
0039: GOTO 12D
.................... // Check 4.5ms space (remote control sends logic low)
.................... SET_TIMER1(0);
003A: CLRF 16
003B: CLRF 17
003C: CLRF 16
003D: NOP
.................... count = 0;
003E: CLRF 25
003F: CLRF 24
.................... while((input(IR_Sensor)) && (count < 5000))
0040: BTFSS 0C.3
0041: GOTO 059
0042: MOVF 25,W
0043: SUBLW 13
0044: BTFSS 03.0
0045: GOTO 059
0046: BTFSS 03.2
0047: GOTO 04C
0048: MOVF 24,W
0049: SUBLW 87
004A: BTFSS 03.0
004B: GOTO 059
.................... count = GET_TIMER1();
004C: MOVF 17,W
004D: MOVWF 7A
004E: MOVF 16,W
004F: MOVWF 77
0050: MOVF 17,W
0051: SUBWF 7A,W
0052: BTFSS 03.2
0053: GOTO 04C
0054: MOVF 77,W
0055: MOVWF 24
0056: MOVF 7A,W
0057: MOVWF 25
0058: GOTO 040
.................... if( (count > 4999) || (count < 4000))
0059: MOVF 25,W
005A: SUBLW 12
005B: BTFSC 03.0
005C: GOTO 064
005D: XORLW FF
005E: BTFSS 03.2
005F: GOTO 06E
0060: MOVF 24,W
0061: SUBLW 87
0062: BTFSS 03.0
0063: GOTO 06E
0064: MOVF 25,W
0065: SUBLW 0F
0066: BTFSS 03.0
0067: GOTO 071
0068: BTFSS 03.2
0069: GOTO 06E
006A: MOVF 24,W
006B: SUBLW 9F
006C: BTFSS 03.0
006D: GOTO 071
.................... return FALSE;
006E: MOVLW 00
006F: MOVWF 78
0070: GOTO 12D
.................... // Read message (32 bits)
.................... for(i = 0; i < 32; i++){
0071: CLRF 26
0072: MOVF 26,W
0073: SUBLW 1F
0074: BTFSS 03.0
0075: GOTO 12B
.................... SET_TIMER1(0);
0076: CLRF 16
0077: CLRF 17
0078: CLRF 16
0079: NOP
.................... count = 0;
007A: CLRF 25
007B: CLRF 24
.................... while(!input(IR_Sensor) && (count < 650))
007C: BTFSC 0C.3
007D: GOTO 095
007E: MOVF 25,W
007F: SUBLW 02
0080: BTFSS 03.0
0081: GOTO 095
0082: BTFSS 03.2
0083: GOTO 088
0084: MOVF 24,W
0085: SUBLW 89
0086: BTFSS 03.0
0087: GOTO 095
.................... count = GET_TIMER1();
0088: MOVF 17,W
0089: MOVWF 7A
008A: MOVF 16,W
008B: MOVWF 77
008C: MOVF 17,W
008D: SUBWF 7A,W
008E: BTFSS 03.2
008F: GOTO 088
0090: MOVF 77,W
0091: MOVWF 24
0092: MOVF 7A,W
0093: MOVWF 25
0094: GOTO 07C
.................... if( (count > 649) || (count < 500))
0095: MOVF 25,W
0096: SUBLW 01
0097: BTFSC 03.0
0098: GOTO 0A0
0099: XORLW FF
009A: BTFSS 03.2
009B: GOTO 0AA
009C: MOVF 24,W
009D: SUBLW 89
009E: BTFSS 03.0
009F: GOTO 0AA
00A0: MOVF 25,W
00A1: SUBLW 01
00A2: BTFSS 03.0
00A3: GOTO 0AD
00A4: BTFSS 03.2
00A5: GOTO 0AA
00A6: MOVF 24,W
00A7: SUBLW F3
00A8: BTFSS 03.0
00A9: GOTO 0AD
.................... return FALSE;
00AA: MOVLW 00
00AB: MOVWF 78
00AC: GOTO 12D
.................... count = 0;
00AD: CLRF 25
00AE: CLRF 24
.................... SET_TIMER1(0);
00AF: CLRF 16
00B0: CLRF 17
00B1: CLRF 16
00B2: NOP
.................... while((input(IR_Sensor)) && (count < 1800))
00B3: BTFSS 0C.3
00B4: GOTO 0CC
00B5: MOVF 25,W
00B6: SUBLW 07
00B7: BTFSS 03.0
00B8: GOTO 0CC
00B9: BTFSS 03.2
00BA: GOTO 0BF
00BB: MOVF 24,W
00BC: SUBLW 07
00BD: BTFSS 03.0
00BE: GOTO 0CC
.................... count = GET_TIMER1();
00BF: MOVF 17,W
00C0: MOVWF 7A
00C1: MOVF 16,W
00C2: MOVWF 77
00C3: MOVF 17,W
00C4: SUBWF 7A,W
00C5: BTFSS 03.2
00C6: GOTO 0BF
00C7: MOVF 77,W
00C8: MOVWF 24
00C9: MOVF 7A,W
00CA: MOVWF 25
00CB: GOTO 0B3
.................... if( (count > 1799) || (count < 400))
00CC: MOVF 25,W
00CD: SUBLW 06
00CE: BTFSC 03.0
00CF: GOTO 0D7
00D0: XORLW FF
00D1: BTFSS 03.2
00D2: GOTO 0E1
00D3: MOVF 24,W
00D4: SUBLW 07
00D5: BTFSS 03.0
00D6: GOTO 0E1
00D7: MOVF 25,W
00D8: SUBLW 01
00D9: BTFSS 03.0
00DA: GOTO 0E4
00DB: BTFSS 03.2
00DC: GOTO 0E1
00DD: MOVF 24,W
00DE: SUBLW 8F
00DF: BTFSS 03.0
00E0: GOTO 0E4
.................... return FALSE;
00E1: MOVLW 00
00E2: MOVWF 78
00E3: GOTO 12D
.................... if( count > 1000) // If space width > 1ms
00E4: MOVF 25,W
00E5: SUBLW 02
00E6: BTFSC 03.0
00E7: GOTO 10A
00E8: XORLW FF
00E9: BTFSS 03.2
00EA: GOTO 0EF
00EB: MOVF 24,W
00EC: SUBLW E8
00ED: BTFSC 03.0
00EE: GOTO 10A
.................... bit_set(ir_code, (31 - i)); // Write 1 to bit (31 - i)
00EF: MOVF 26,W
00F0: SUBLW 1F
00F1: MOVWF 28
00F2: CLRF 7A
00F3: CLRF 79
00F4: CLRF 78
00F5: MOVLW 01
00F6: MOVWF 77
00F7: MOVF 28,W
00F8: MOVWF 29
00F9: BTFSC 03.2
00FA: GOTO 101
00FB: LSLF 77,F
00FC: RLF 78,F
00FD: RLF 79,F
00FE: RLF 7A,F
00FF: DECFSZ 29,F
0100: GOTO 0FB
0101: MOVF 77,W
0102: IORWF 20,F
0103: MOVF 78,W
0104: IORWF 21,F
0105: MOVF 79,W
0106: IORWF 22,F
0107: MOVF 7A,W
0108: IORWF 23,F
0109: GOTO 129
.................... else // If space width < 1ms
.................... bit_clear(ir_code, (31 - i)); // Write 0 to bit (31 - i)
010A: MOVF 26,W
010B: SUBLW 1F
010C: MOVWF 28
010D: CLRF 7A
010E: CLRF 79
010F: CLRF 78
0110: MOVLW 01
0111: MOVWF 77
0112: MOVF 28,W
0113: MOVWF 29
0114: BTFSC 03.2
0115: GOTO 11C
0116: LSLF 77,F
0117: RLF 78,F
0118: RLF 79,F
0119: RLF 7A,F
011A: DECFSZ 29,F
011B: GOTO 116
011C: MOVLW FF
011D: XORWF 77,F
011E: XORWF 78,F
011F: XORWF 79,F
0120: XORWF 7A,F
0121: MOVF 77,W
0122: ANDWF 20,F
0123: MOVF 78,W
0124: ANDWF 21,F
0125: MOVF 79,W
0126: ANDWF 22,F
0127: MOVF 7A,W
0128: ANDWF 23,F
0129: INCF 26,F
012A: GOTO 072
.................... }
.................... return TRUE;
012B: MOVLW 01
012C: MOVWF 78
012D: MOVLP 00
012E: GOTO 148 (RETURN)
.................... }
.................... void main() {
012F: MOVLW 72
0130: MOVLB 01
0131: MOVWF 19
0132: MOVLB 03
0133: CLRF 0C
0134: MOVLB 02
0135: CLRF 12
0136: CLRF 11
.................... setup_oscillator(OSC_8MHZ|OSC_PLL_ON); // Set internal oscillator to 32MHz (8MHz and PLL)
0137: MOVLW F0
0138: MOVLB 01
0139: MOVWF 19
.................... output_a(0);
013A: MOVLB 02
013B: CLRF 0C
.................... set_tris_a(8);
013C: MOVLW 08
013D: MOVLB 01
013E: MOVWF 0C
.................... SETUP_TIMER_1(T1_INTERNAL | T1_DIV_BY_8);
013F: MOVLB 02
0140: BCF 1D.3
0141: MOVLW 35
0142: MOVLB 00
0143: MOVWF 18
0144: CLRF 19
.................... while(TRUE){
.................... while(input(IR_Sensor)); // Wait until IR_Sensor pin falls
0145: BTFSC 0C.3
0146: GOTO 145
.................... if(nec_remote_read()){
0147: GOTO 003
0148: MOVF 78,F
0149: BTFSC 03.2
014A: GOTO 1AC
.................... if(ir_code == 0x40BF00FF)
014B: INCFSZ 20,W
014C: GOTO 15C
014D: MOVF 21,F
014E: BTFSS 03.2
014F: GOTO 15C
0150: MOVF 22,W
0151: SUBLW BF
0152: BTFSS 03.2
0153: GOTO 15C
0154: MOVF 23,W
0155: SUBLW 40
0156: BTFSS 03.2
0157: GOTO 15C
.................... output_toggle(PIN_A0);
0158: MOVLW 01
0159: MOVLB 02
015A: XORWF 0C,F
015B: MOVLB 00
.................... if(ir_code == 0x40BF807F)
015C: MOVF 20,W
015D: SUBLW 7F
015E: BTFSS 03.2
015F: GOTO 170
0160: MOVF 21,W
0161: SUBLW 80
0162: BTFSS 03.2
0163: GOTO 170
0164: MOVF 22,W
0165: SUBLW BF
0166: BTFSS 03.2
0167: GOTO 170
0168: MOVF 23,W
0169: SUBLW 40
016A: BTFSS 03.2
016B: GOTO 170
.................... output_toggle(PIN_A1);
016C: MOVLW 02
016D: MOVLB 02
016E: XORWF 0C,F
016F: MOVLB 00
.................... if(ir_code == 0x40BF40BF)
0170: MOVF 20,W
0171: SUBLW BF
0172: BTFSS 03.2
0173: GOTO 184
0174: MOVF 21,W
0175: SUBLW 40
0176: BTFSS 03.2
0177: GOTO 184
0178: MOVF 22,W
0179: SUBLW BF
017A: BTFSS 03.2
017B: GOTO 184
017C: MOVF 23,W
017D: SUBLW 40
017E: BTFSS 03.2
017F: GOTO 184
.................... output_toggle(PIN_A2);
0180: MOVLW 04
0181: MOVLB 02
0182: XORWF 0C,F
0183: MOVLB 00
.................... if(ir_code == 0x40BF20DF)
0184: MOVF 20,W
0185: SUBLW DF
0186: BTFSS 03.2
0187: GOTO 198
0188: MOVF 21,W
0189: SUBLW 20
018A: BTFSS 03.2
018B: GOTO 198
018C: MOVF 22,W
018D: SUBLW BF
018E: BTFSS 03.2
018F: GOTO 198
0190: MOVF 23,W
0191: SUBLW 40
0192: BTFSS 03.2
0193: GOTO 198
.................... output_toggle(PIN_A4);
0194: MOVLW 10
0195: MOVLB 02
0196: XORWF 0C,F
0197: MOVLB 00
.................... if(ir_code == 0x40BFA05F)
0198: MOVF 20,W
0199: SUBLW 5F
019A: BTFSS 03.2
019B: GOTO 1AC
019C: MOVF 21,W
019D: SUBLW A0
019E: BTFSS 03.2
019F: GOTO 1AC
01A0: MOVF 22,W
01A1: SUBLW BF
01A2: BTFSS 03.2
01A3: GOTO 1AC
01A4: MOVF 23,W
01A5: SUBLW 40
01A6: BTFSS 03.2
01A7: GOTO 1AC
.................... output_toggle(PIN_A5);
01A8: MOVLW 20
01A9: MOVLB 02
01AA: XORWF 0C,F
01AB: MOVLB 00
.................... }
01AC: GOTO 145
.................... }
.................... }
....................
01AD: SLEEP

Configuration Fuses:
Word 1: 3F84 INTRC_IO NOWDT PUT NOMCLR NOPROTECT NOCPD BROWNOUT NOCLKOUT IESO FCMEN
Word 2: 1EFF NOWRT PLL_SW STVREN BORV19 NODEBUG NOLVP
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Mar 13, 2021 7:02 pm     Reply with quote

Denny9167 wrote:
I noticed this in the code:

[code]

set_tris_a(8);

[code/]

Shouldn’t this be “ set_tris_a(0x8);” for this chip?

No. 0x8 is the same as 8.

Also, you are doing code blocks incorrectly. Notice how it didn't work ?
The slash goes before the word 'code', like this: /code
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Mar 13, 2021 7:04 pm     Reply with quote

What components are you using for the IR receiver and transmitter ?
Post the part numbers. What are the circuit connections you are using ?
Denny9167



Joined: 15 Feb 2021
Posts: 49

View user's profile Send private message Send e-mail

PostPosted: Sun Mar 14, 2021 6:42 am     Reply with quote

PCM programmer wrote:
What components are you using for the IR receiver and transmitter ?
Post the part numbers. What are the circuit connections you are using ?


Thanks again for the typo correction, anyway I’m using a TSOP4838 receiver
Pins are connected in this arrangement pin 1 connected to pin 4 on the Chip, with a 10k pull up resistor to Vdd, pin 2 of receiver connected to GND, and pin 3 to Vdd, the LED’s and resistors are connected exactly like the schematic
Shown by the author, I purchased an NEC remote off of Amazon, and depressed the keys that correspond to what’s in the code. Maybe the remote isn’t functioning properly. Does the list file look OK? Thanks PCM!
temtronic



Joined: 01 Jul 2010
Posts: 9241
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Mar 14, 2021 7:32 am     Reply with quote

Assuming you have a scope, attach X10 probe of scope to SEE the signal going to the PIC......
I can't tell if the code is correct unless I had a transmitter and rcvr for testing.... but a scope will SHOW you what's going on.
Denny9167



Joined: 15 Feb 2021
Posts: 49

View user's profile Send private message Send e-mail

PostPosted: Sun Mar 14, 2021 1:06 pm     Reply with quote

temtronic wrote:
Assuming you have a scope, attach X10 probe of scope to SEE the signal going to the PIC......
I can't tell if the code is correct unless I had a transmitter and rcvr for testing.... but a scope will SHOW you what's going on.


I will thanks
Ttelmah



Joined: 11 Mar 2010
Posts: 19537

View user's profile Send private message

PostPosted: Mon Mar 15, 2021 12:40 am     Reply with quote

If you have an Android smartphone, you can download the remote control
app for this. Would give you a second 'test source' to see if this is the
problem.

As a comment though, the code being used is 'time critical' on the I/O.
This is why the original code used fast_io. You have substituted 'fixed_io'.
Fixed_io, does not give the speed advantages of fast_io. You should put the
code back to using fast_io, and set tris A to 0b00001000. There will be
timing issues with the current code because of this....

On the LED's coming on, the LAT register, contains random values at boot,
unless you load it. output_a(0), will set all the output latches to zero.
If you look in the data sheet, 'value at PR', is given as XX -XXX.
Denny9167



Joined: 15 Feb 2021
Posts: 49

View user's profile Send private message Send e-mail

PostPosted: Mon Mar 15, 2021 5:22 am     Reply with quote

I believe I’ve discovered at least part of the problem, I don’t have the LP filter on the receiver, would supply ripple disrupt the signal? I believe the author recommends a 47uf capacitor.
Ttelmah



Joined: 11 Mar 2010
Posts: 19537

View user's profile Send private message

PostPosted: Mon Mar 15, 2021 5:50 am     Reply with quote

Good decoupling is _essential_ on all electronics. 0.1uF ceramic capacitors
close to the supply legs of all devices, and a larger decoupling capacitor,
depending on the nature of the actual supply.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2, 3  Next
Page 1 of 3

 
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