Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Nigels IR Question

Status
Not open for further replies.

AtomSoft

Well-Known Member
Ok Im following Nigels IR Tutorial 5. I have modified it just alittle to fit the 18F1320. I wanted to know if some one can skim over the code and tell me if everything seems ok so far...

Also Here is the schematic for the IR module i altered from Nigels Tuts... Does it also seem ok?
**broken link removed**

Just asking for thoughts and any input. Thanks for all the great info Nigel!
Keep up the good work..

Code:
 ;Tutorial 5.2 - Nigel Goodwin 2002
;Sony SIRC IR transmitter
	LIST	p=18F1320		;tell assembler what chip we are using
	include	<p18F1320.inc>		;include the defaults for the chip
	CONFIG	OSC = INTIO1, WDT = OFF, LVP = OFF, DEBUG = ON			;sets the configuration settings (oscillator type etc.)

	cblock 	0x20 			;start of general purpose registers
		count1 			;used in delay routine
		counta 			;used in delay routine 
		countb
		count
		Delay_Count
		Bit_Cntr
		Data_Byte
		Dev_Byte
		Rcv_Byte
		Pulse
	endc
	

IR_PORT	Equ	PORTB
IR_TRIS	Equ	TRISB
IR_Out	Equ	0x01
Ser_Out	Equ	0x01
SW1	Equ	7			;set constants for the switches
SW2	Equ	6
SW3	Equ	5
SW4	Equ	4

TV_ID		Equ	0x01			;TV device ID

But1		Equ	0x00			;numeric button ID's
But2		Equ	0x01
But3		Equ	0x02
But4		Equ	0x03
But5		Equ	0x04
But6		Equ	0x05
But7		Equ	0x06
But8		Equ	0x07
But9		Equ	0x08
ProgUp		Equ	d'16'
ProgDn		Equ	d'17'
VolUp		Equ	d'18'
VolDn		Equ	d'19'


	org	0x0000			;org sets the origin, 0x0000 for the 16F628,
	goto	Start			;this is where the program starts running

	org	0x004	

Start	;movlw	0x07
		;movwf	CMCON			;turn comparators off (make it like a 16F84)
		movlw	0x62 				; 4MHz clock select
    	movwf	OSCCON
		clrf	IR_PORT			;make PortB outputs low
 
   		;bsf 	STATUS,		RP0	;select bank 1
   		movlw 	b'11111101'		;set PortB all inputs, except RB1
   		movwf 	IR_TRIS
		movlw	0xff
		movwf	PORTA
		;bcf	STATUS,		RP0	;select bank 0

Read_Sw
		btfss	PORTA,	SW1
		call	Switch1
		btfss	PORTA,	SW2
		call	Switch2
		btfss	PORTA,	SW3
		call	Switch3
		btfss	PORTA,	SW4
		call	Switch4
		call	Delay27
		goto	Read_Sw

Switch1		movlw	ProgUp
		call	Xmit_RS232
		retlw	0x00

Switch2		movlw	ProgDn
		call	Xmit_RS232
		retlw	0x00

Switch3		movlw	VolUp
		call	Xmit_RS232
		retlw	0x00

Switch4		movlw	VolDn
		call	Xmit_RS232
		retlw	0x00

TX_Start	movlw	d'92'
		call	IR_pulse
		movlw	d'23'
		call	NO_pulse
		retlw	0x00

TX_One		movlw	d'46'
		call	IR_pulse
		movlw	d'23'
		call	NO_pulse
		retlw	0x00

TX_Zero		movlw	d'23'
		call	IR_pulse
		movlw	d'23'
		call	NO_pulse
		retlw	0x00

IR_pulse			 	
		MOVWF	count		;  Pulses the IR led at 38KHz
irloop		BSF	IR_PORT,	IR_Out 
		NOP			;
		NOP			;
		NOP			;
		NOP			; 
		NOP			;
		NOP			;
		NOP			;
		BCF	IR_PORT,	IR_Out
		NOP			;
		NOP			;
		NOP			;
		NOP			;
		NOP			;
		NOP			;	
		NOP			;
		NOP			;	
		NOP			;
		NOP			;
		NOP
		NOP
		NOP			;
		NOP			;
		DECFSZ	count,F
		GOTO 	irloop	
		RETLW	0

NO_pulse			 	
		MOVWF	count		;  Doesn't pulse the IR led
irloop2		BCF	IR_PORT,	IR_Out 
		NOP			;
		NOP			;
		NOP			;
		NOP			;
		NOP			;
		NOP			;
		NOP			;
		NOP			; 
		NOP			;
		NOP			;
		NOP			;
		BCF	IR_PORT,	IR_Out
		NOP			;
		NOP			;	
		NOP			;
		NOP			;	
		NOP			;
		NOP			;
		NOP
		NOP
		NOP			;
		NOP			;
		DECFSZ	count,F
		GOTO 	irloop2	
		RETLW	0

Xmit_RS232      MOVWF   Data_Byte            	;move W to Data_Byte
                MOVLW   0x07                 	;set 7 DATA bits out
                MOVWF   Bit_Cntr
                call	TX_Start		;send start bit
Ser_Loop        RRCF     Data_Byte , f        	;send one bit
                BTFSC   STATUS    , C
                call	TX_One
                BTFSS   STATUS    , C
                call	TX_Zero
                DECFSZ  Bit_Cntr  , f        	;test if all done
                GOTO    Ser_Loop
						;now send device data
		movlw	D'1'
		movwf	Dev_Byte		;set device to TV
		MOVLW   0x05                 	;set 5 device bits out
                MOVWF   Bit_Cntr
Ser_Loop2       RRCF     Dev_Byte , f        	;send one bit
                BTFSC   STATUS    , C
                call	TX_One
                BTFSS   STATUS    , C
                call	TX_Zero
                DECFSZ  Bit_Cntr  , f        	;test if all done
                GOTO    Ser_Loop2
                retlw	0x00



;Delay routines

Delay255	movlw	0xff		;delay 255 mS
		goto	d0
Delay100	movlw	d'100'		;delay 100mS
		goto	d0
Delay50		movlw	d'50'		;delay 50mS
		goto	d0
Delay27		movlw	d'27'		;delay 27mS
		goto	d0
Delay20		movlw	d'20'		;delay 20mS
		goto	d0
Delay5		movlw	0x05		;delay 5.000 ms (4 MHz clock)
d0		movwf	count1
d1		movlw	0xC7
		movwf	counta
		movlw	0x01
		movwf	countb
Delay_0		decfsz	counta, f
		goto	$+2
		decfsz	countb, f
		goto	Delay_0

		decfsz	count1	,f
		goto	d1
		retlw	0x00

;end of Delay routines

	end
 
hi Atom,
The PORTB LED flashes.
EDIT: reading the pic crossed eyed.!
 
Last edited:
AtomSoft said:
I dont understand this responce ..... what program is that? Looks cool!

hi atom,
Thats the www.oshonsoft.com PIC simulator. You can download the trial version.

I think you have RA5 set as MCLR.!

The scope on the sim shows the pulse bursts varying in length for each switch, except RA5..
 
AtomSoft said:
I dont understand this responce ..... what program is that? Looks cool!

I edited my text I had misread the picture, sorry about that...:eek:
 
RA5 is MCLR on both pics ... the original 16F628 which this code was originally for and the 18F1320 both have MCLR on RA5... what would you suggest i do then?
 
AtomSoft said:
RA5 is MCLR on both pics ... the original 16F628 which this code was originally for and the 18F1320 both have MCLR on RA5... what would you suggest i do then?

hi,
Look at the CONFIG line at the top of the program.;)

Use the microchip templates on your hard drive.

here:
C:\Program Files\Microchip\MPASM Suite\Template\Code\18F1320TEMP.ASM

Do you follow.?

EDIT: added CONFIG for MCLR
 
Last edited:
AtomSoft said:
OK i have that program install but how do i simulate a button press?
hi,
Use the IDE tools to show the microprocessor view [make sure you have
chosen the 18F1320]

Assemble and load the program into the SIm.
Run it at ultimate speed.
Mouse click the PORTA pins of the micro view to change their state.

Click the 'T' box to toggle the pin..

OK.?
 
yeah i got that done... listen i changed well added the MCLRE = OFF and its still not enabled in the simulator after reopen the file... Thanks for this help again!
 
i guess i should have known that by now lol ive seen it so many places lol thanks alot. Ill move the commands down from 5 so 4 and 3 would be next :
Code:
SW1	Equ	7			;set constants for the switches
SW2	Equ	6
SW3	Equ	4
SW4	Equ	3
 
AtomSoft said:
i guess i should have known that by now lol ive seen it so many places lol thanks alot. Ill move the commands down from 5 so 4 and 3 would be next :
Code:
SW1	Equ	7			;set constants for the switches
SW2	Equ	6
SW3	Equ	4
SW4	Equ	3

hi atom,
Lets know how you get on with the PIC Sim, if you have any questions about it, please ask..:)
 
This is my code so far i will post schematics in a minute, Im having so many issues with this in MPLAB SIM... For some reason PORTA wont set HIGH and well just so many issues from that alone...

Code:
;Tutorial 5.2 - Nigel Goodwin 2002
;Sony SIRC IR transmitter
	LIST	p=18F1320		;tell assembler what chip we are using
	include	<p18F1320.inc>		;include the defaults for the chip
	CONFIG	OSC = INTIO1, WDT = OFF, LVP = OFF, DEBUG = ON		;sets the configuration settings (oscillator type etc.)

	cblock 	0x20 			;start of general purpose registers
		count1 			;used in delay routine
		counta 			;used in delay routine 
		countb
		count
		Delay_Count
		Bit_Cntr
		Data_Byte
		Dev_Byte
		Rcv_Byte
		Pulse
	endc
	

IR_PORT	Equ	PORTB
IR_TRIS	Equ	TRISB
IR_Out	Equ	0x01
Ser_Out	Equ	0x01
SW1	Equ	7			;set constants for the switches
SW2	Equ	6
SW3	Equ	4

TV_ID		Equ	0x01			;TV device ID

But1		Equ	0x00			;numeric button ID's
But2		Equ	0x01
But3		Equ	0x02

		org	0x00
Start
		movlw	0x62			; 4MHz clock select
    	movwf	OSCCON
		clrf	IR_PORT			;make PortB outputs low
 
   		movlw 	b'11111101'		;set PortB all inputs, except RB1
   		movwf 	IR_TRIS
		movlw 	b'11111111'
	    movwf	TRISA
		movlw 	b'11111111'
		movwf	PORTA

Read_Sw
		btfss	PORTA, SW1
		call	Switch1
		btfss	PORTA, SW2
		call	Switch2
		btfss	PORTA, SW3
		call	Switch3
		;call	Delay27
		goto	Read_Sw

Switch1		movlw	But1
		call	Xmit_RS232
		retlw	0x00

Switch2		movlw	But2
		call	Xmit_RS232
		retlw	0x00

Switch3		movlw	But3
		call	Xmit_RS232
		retlw	0x00

TX_Start	movlw	d'92'
		call	IR_pulse
		movlw	d'23'
		call	NO_pulse
		retlw	0x00

TX_One		movlw	d'46'
		call	IR_pulse
		movlw	d'23'
		call	NO_pulse
		retlw	0x00

TX_Zero		movlw	d'23'
		call	IR_pulse
		movlw	d'23'
		call	NO_pulse
		retlw	0x00

IR_pulse			 	
		MOVWF	count		;  Pulses the IR led at 38KHz
irloop		BSF	IR_PORT,	IR_Out 
		NOP			;
		NOP			;
		NOP			;
		NOP			; 
		NOP			;
		NOP			;
		NOP			;
		BCF	IR_PORT,	IR_Out
		NOP			;
		NOP			;
		NOP			;
		NOP			;
		NOP			;
		NOP			;	
		NOP			;
		NOP			;	
		NOP			;
		NOP			;
		NOP
		NOP
		NOP			;
		NOP			;
		DECFSZ	count,F
		GOTO 	irloop	
		RETLW	0

NO_pulse			 	
		MOVWF	count		;  Doesn't pulse the IR led
irloop2		BCF	IR_PORT,	IR_Out 
		NOP			;
		NOP			;
		NOP			;
		NOP			;
		NOP			;
		NOP			;
		NOP			;
		NOP			; 
		NOP			;
		NOP			;
		NOP			;
		BCF	IR_PORT,	IR_Out
		NOP			;
		NOP			;	
		NOP			;
		NOP			;	
		NOP			;
		NOP			;
		NOP
		NOP
		NOP			;
		NOP			;
		DECFSZ	count,F
		GOTO 	irloop2	
		RETLW	0

Xmit_RS232      MOVWF   Data_Byte            	;move W to Data_Byte
                MOVLW   0x07                 	;set 7 DATA bits out
                MOVWF   Bit_Cntr
                call	TX_Start		;send start bit
Ser_Loop        RRCF     Data_Byte , f        	;send one bit
                BTFSC   STATUS    , C
                call	TX_One
                BTFSS   STATUS    , C
                call	TX_Zero
                DECFSZ  Bit_Cntr  , f        	;test if all done
                GOTO    Ser_Loop
						;now send device data
		movlw	D'1'
		movwf	Dev_Byte		;set device to TV
		MOVLW   0x05                 	;set 5 device bits out
                MOVWF   Bit_Cntr
Ser_Loop2       RRCF     Dev_Byte , f        	;send one bit
                BTFSC   STATUS    , C
                call	TX_One
                BTFSS   STATUS    , C
                call	TX_Zero
                DECFSZ  Bit_Cntr  , f        	;test if all done
                GOTO    Ser_Loop2
                retlw	0x00



;Delay routines

Delay255	movlw	0xff		;delay 255 mS
		goto	d0
Delay100	movlw	d'100'		;delay 100mS
		goto	d0
Delay50		movlw	d'50'		;delay 50mS
		goto	d0
Delay27		movlw	d'27'		;delay 27mS
		goto	d0
Delay20		movlw	d'20'		;delay 20mS
		goto	d0
Delay5		movlw	0x05		;delay 5.000 ms (4 MHz clock)
d0		movwf	count1
d1		movlw	0xC7
		movwf	counta
		movlw	0x01
		movwf	countb
Delay_0		decfsz	counta, f
		goto	$+2
		decfsz	countb, f
		goto	Delay_0

		decfsz	count1	,f
		goto	d1
		retlw	0x00

;end of Delay routines

	end
 
hi atom,
What baud rate is the IR being transmitted at.?
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top