Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 17:38 05 May 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Micromite MK2: IR receiver for NEC

     Page 2 of 2    
Author Message
Grassy
Newbie

Joined: 06/07/2014
Location: Australia
Posts: 12
Posted: 06:40pm 30 Nov 2014
Copy link to clipboard 
Print this post

On the subject of future documentation, I think what is needed for a better understanding of a concept whether it be C functions or MMBasic commands is example code after “every” command explanation.

This is what made the PICAXE system so superior to everything that came before it for beginners. After describing each BASIC command in the manual an example was given.

This example code was often very simple but no matter how bogged down I became in the description of the command I was always able to try the example and this cleared up how it was meant to work. I guess experienced programmers tend to overlook the importance of examples for what may seem obvious commands or concepts when writing manuals but believe me if this could be considered for any future work either on the MMBasic manual itself or complex additions like C functions it would be very welcome.
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8592
Posted: 12:44am 05 Dec 2014
Copy link to clipboard 
Print this post

New version that should work on any pin that supports an interrupt on both 28 and 40 pin processors. Help testing on a 40 pin chip would be appreciated.

IMPORTANT: Get rid of the spaces the board puts into the P28$ and p40$ strings.


cpu 48
option explicit
option default none
const IRpin=7
dim as integer IRreceived=0,IRread=0,IRbuffer(8),portnum,pinnum,i;
i= getpin(IRpin,portnum,pinnum)
setpin IRpin,intl,readpulses,pullup
do
do while IRreceived<>IRread
print hex$(IRbuffer(IRread),8)
IRread=(IRread+1) mod 8
loop
loop
end
'
readpulses:
local i as integer
i=NECreceive(portnum,pinnum)
if ((IRreceived+1) mod 8) <> IRread then 'check for buffer full
IRbuffer(IRreceived)=i
IRreceived=(IRreceived+1) mod 8
endif
ireturn
'
function getpin(MMpin as integer,portnum as integer,pinnum as integer) as integer
const P28$="N/AA00A01B00B01B02B03N/AA02A03B04A04N/AB05B06B07B08B09 N/AN/AB10B11B12B13B14B15N/AN/A"
const P40$="B09C06C07C08C09N/AN/AB10B11B12B13A10A07B14B15N/AN/AN/A A00A01B00B01B02B03C00C01C02N/AN/AA02A03A08B04A04A09C03C04C05 N/AN/AB05B06B07B08"
local integer i
local a$ length 3
i=(MMpin-1)*3 +1
if (peek(word &HBF80F220) and &HFFFFFFF) = &H6610053 then
if MMpin>=1 and MMpin<=28 then
a$=mid$(p28$,i,3)
else
a$="N/A"
endif
else
if MMpin>=1 and MMpin<=40 then
a$=mid$(p40$,i,3)
else
a$="N/A"
endif
endif
if a$="N/A" then
getpin=0
else
portnum=asc(left$(a$,1))-65
pinnum=val(right$(a$,2))
getpin=1
endif
end function
'
CFunction NECreceive
00000000
27bdff78 8c820000 24030001 14430003 8c840004 10800008 3c06bf88 24030002
14430003 3c06bf88 50800004 24c66220 10000002 24c66020 24c66120 34038010
3c02bf80 ac430600 8ca20000 24040001 00442004 8cc20000 00441024 1040fffd
3c02bf80 ac400610 00003821 34039c40 10000021 24090021 8cc50000 00a42824
10a00005 00000000 8c450610 00a3282b 14a0fff9 00000000 8c480610 00072880
03a52821 aca80000 8c450610 00a3282b 10a00003 00000000 ac400610 24e70001
8cc50000 00a42824 14a00005 00000000 8c450610 00a3282b 14a0fff9 00000000
8c450610 00a3282b 54a00001 ac400610 10e9000e 8fa80000 8c450610 00a3282b
14a0ffdd 00000000 240400ff 24020001 10e2002e 00002821 24e7fffe 2ce7001f
14e0002a 00002021 8fa80000 00084082 00003021 00002821 27a30004 00001021
240a0001 24070020 8c640000 0104202b 50800006 24420001 004a2004 00044fc3
00c43025 00a92825 24420001 1447fff6 24630004 00c01021 38c3ff00 7c633a00
7c627a04 7c463e00 00063027 30c600ff 7cc2fe04 304700ff 00002021 1467000b
00002821 7c473c00 54e60009 00801021 7c627a04 7cc23804 7c02bc04 7c02fe04
00003021 00402021 00c02821 00801021 00a01821 03e00008 27bd0088
End CFunction


long long NECreceive(long long *portname, long long *pinnum){
#define tmr1con *(volatile unsigned int *)0xbf800600 //timer 1 configuration register
#define tmr1 *(volatile unsigned int *)0xbf800610 //timer 1 counter
unsigned int i,j,k,bitlength,log[33];
unsigned int volatile * myport;
union utype{
unsigned long long b;
unsigned char a[8];
unsigned long c[2];
}buffer;
if(*portname==0) myport=(volatile unsigned int *)0xbf886020;
if(*portname==1) myport=(volatile unsigned int *)0xbf886120;
if(*portname==2) myport=(volatile unsigned int *)0xbf886220;
tmr1con=0x8010; //turn on with scale 8
j=1<<*pinnum;
i=0;
buffer.b=0;
while ((*myport & j)==0); //wait for A.0 (pin 2) to go high after the intial long low
tmr1=0; //reset the timer
while (tmr1<40000){
while (((*myport & j)!=0) && (tmr1<40000));
log=tmr1;
if (tmr1<40000){
tmr1=0;
i++;
}
while (((*myport & j)==0) && (tmr1<40000));
if (tmr1<40000) tmr1=0;
if (i==33) break;
}
if(i==1) return 0xFF; //Repeat code
if(i>1 && i<33) return 0; //invalid code
bitlength=log[0]/4; //establish a test bit length
for (k=0;k<32;k++){
if(log[k+1]>bitlength) buffer.b=buffer.b | (1<<k);
}
buffer.a[1]=~buffer.a[1];
buffer.a[3]=~buffer.a[3];
if ((buffer.a[0]!=buffer.a[1]) || (buffer.a[2]!=buffer.a[3])) return 0;
buffer.a[1]=buffer.a[0];
buffer.a[0]=buffer.a[2];
buffer.a[2]=0;
buffer.a[3]=0;
buffer.c[1]=0;
return buffer.b;
}
 
     Page 2 of 2    
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024