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.

IR Fan

Status
Not open for further replies.
You don't need any special wires the Junebug is already wired for the UART tool. The PICkit2 2.40 software (not MPLAB) has a UART tool (TTL rs232 terminal) built in and free. Just program the 18F1320 normally, turn off DIP switches 1,2,3 and turn on 4 & 5 (TX, RX)
Run the PICkit2 software and from Tools / UART Tool...
Set your baud rate (9600 is the default) then press connect.

Try it with reaction timer on my site *uses Swordfish BASIC
If you want the hex file I'll be happy to post it here.
 
Im tired so ima go to bed its 11:30pm here um.. ill read in the morning and try to amaze you all lol at least im trying (and having fun) (good night to all) (morning to some)
 
wow that UART stuff is cool just tried it and nice! but iwould like to know(or will figure it out soon) how its done like the inners of making it work. To figure it out im going to check the schematics of junebug to determin what parts from the junebug has to be copied off and i need to buy some 18F1320s. I see you are using the 18F2550 to connect the USB. I would need to know how to do this. Or is it possible just to use the max232 for this but on a serial cable?
 
i got it sort of ... i used a Max232CPE and a DB9 but for some reason it locks
up well doesnt lock up but it doesnt let me send data to it in hyper terminal. Any thoughts?
 
LOL it was the Flow Control
EDIT:
Working Fine now 100% thx im going to study the code now and have some extra fun. Heres a picture (i love pictures) lol

**broken link removed**
 
The max232 is a handy chip for sure.
Here's some food for thought.
As long as you don't damage the bootloader on the Junebug its possible to use the Junebugs 18F2550 as an experimenter.
Some possible programs and I'll look them up later today would be
FT232R emulator (use your Junebug as a standalone USB to TTL RS232 adapter)
PICkit Serial anaylzer, its similar to a PICkit2 but I've yet to make it work.
Remember your Junebug has its own ICD connector (first 5 pins on the top 16pin connector) can be programmed and debugged from another Junebug or PICkit2 (you'll need to add a 22k resistor to debug pins1 & 3)
That connector also has the 6 pin PICkit2 pinout (last 6 pins) and unused I/O is available with the remaining 5pins.
 
how can i copy it out? Or where can i download the bootloader? SO i can purchase a few 2550's.

Code:
Junebug PIC18F1320

      A - PORTA Status
      B - PORTB Status
      C - Clear PORTA bits 1,2,3,4,6,7
      D - Clear PORTB bits 0,5
      H - Hello World!
      L - Flash LEDs
1,2,3,4,6,7 - Toggle PORTA pins
0,5 - Toggle PORTB pins
<ENTER> - Display menu
Modded by Jason aka AtomSoft, thx futz!

Thats my menu lol
I used most PORT A because that CON3 has 1-4 so easier connection. Um i might buy a couple of things from you this week so be prepared. I added it to my IR fan project so i can control my fans from this also....
 
I was thinking but got confused again lol

Look at the below code all in bold is added/edited.

I change the #3 input as a example on selecting PortA or PortB pin 3 toggling

to select PORTA Pin 3 type QA3
for PORTB pin 3 type QB3

havent tested it but looks ok in theory lol

Code:
			list	p=18F1320
		include	<p18f1320.inc>
		CONFIG	OSC=INTIO2,WDT=OFF,MCLRE=ON,LVP=OFF

		cblock	0x00
			buff2,buff3,char,numr,bitnum,loop1,loop2,temp1,temp2
		endc

		org		0x0000
		goto	init

hello	db		0x0d,0x0a,"Hello World!",0x0d,0x0a,0x00
pa_val	db		0x0d,0x0a,"PortA = ",0x00
pb_val	db		0x0d,0x0a,"PortB = ",0x00
string3	db		0x0d,0x0a,"PORTA cleared",0x0d,0x00
string4	db		0x0d,0x0a,"PORTB cleared",0x0d,0x00
string5	db		0x0d,0x0a,"RA1 toggled",0x0d,0x00
string6	db		0x0d,0x0a,"RA4 toggled",0x0d,0x00
string7	db		0x0d,0x0a,"RA6 toggled",0x0d,0x00
string8	db		0x0d,0x0a,"RA7 toggled",0x0d,0x00
string9	db		0x0d,0x0a,"RB0 toggled",0x0d,0x00
stringa	db		0x0d,0x0a,"RB2 toggled",0x0d,0x00
stringb	db		0x0d,0x0a,"RB3 toggled",0x0d,0x00
stringc	db		0x0d,0x0a,"RB5 toggled",0x0d,0x00
stringd	db		0x0d,0x0a,"LEDs flashed",0x0d,0x00 ;[b]
stringe	db		0x0d,0x0a,"RA3 toggled",0x0d,0x00  ;[/b]
menu	db		0x0d,0x0a,0x0d,0x0a,"Junebug PIC18F1320",0x0d,0x0a,0x0d,0x0a
		db		"      A - PORTA Status",0x0d,0x0a
		db		"      B - PORTB Status",0x0d,0x0a
		db		"      C - Clear PORTA bits 1,2,3,4,6,7",0x0d,0x0a
		db		"      D - Clear PORTB bits 0,5",0x0d,0x0a
		db		"      H - Hello World!",0x0d,0x0a
		db		"      L - Flash LEDs",0x0d,0x0a
		db		"1,2,3,4,6,7 - Toggle PORTA pins ",0x0d,0x0a
		db		"0,5 - Toggle PORTB pins ",0x0d,0x0a
		db		"<ENTER> - Display menu",0x0d,0x0a
		db		"Modded by Jason aka AtomSoft, thx futz!",0x0d,0x0a,0x0d,0x0a,0x00

init	bsf		OSCCON,IRCF2	;set to 8MHz clock
		bsf		OSCCON,IRCF1
		bsf		OSCCON,IRCF0
		setf	ADCON1			;set PortA to all digital
		clrf	TRISA			;set PortA pins to outputs
		clrf	LATA			;turn off LEDs
		movlw	b'00010010'		;set PORTB data directions
		movwf	TRISB
		call	rs_init			;init rs232

		movlw	menu			;send menu
		call	strsend

;************************************************************
;* main - poll rs232 for menu commands and branch accordingly
loop	call	rs_recv			;wait for a char
		movwf	numr			;save as numeral
		andlw	b'01011111'		;convert to upper case
		movwf	char			;save as uppercase char

		movlw	"L"				;is it 'L'?
		cpfseq	char
		goto	cont01			;no, continue
L2		call	flash			;yes, flash leds
		movlw	stringd
		call	strsend
		call	showa
		goto	loop			;go again
cont01	movlw	"H"				;is it 'H'?
		cpfseq	char
		goto	cont02
H2		movlw	hello			;yes, send "Hello World!"
		call	strsend
		goto	loop			;go again
cont02	movlw	"A"				;is it 'A'?
		cpfseq	char
		goto	cont03			;no, continue
A2		call	showa
		goto	loop			;go again
cont03	movlw	"B"				;is it 'B'?
		cpfseq	char			; [b]
		goto	cont03a			;no, continue [/b]
B2		call	showb
		goto	loop			;  [b]
cont03a	movlw	"Q"				;is it 'Q'?
		cpfseq	char
		goto	cont04			;no, continue
Q2		call	showq
		goto	loop			;go again  [/b]
cont04	movlw	"C"				;is it 'C'?
		cpfseq	char
		goto	cont05
C2		movlw	b'00101101'		;clear PORTA bits 1,4,6,7
		andwf	LATA
		movlw	string3
		call	strsend
		call	showa			;display PORTA status
		goto	loop			;go again
cont05	movlw	"D"				;is it 'D'?
		cpfseq	char
		goto	cont06
D2		movlw	b'11010010'		;clear PORTB
		andwf	LATB
		movlw	string4
		call	strsend
		call	showb			;display PORTB status
		goto	loop			;go again
cont06	movlw	0x0d			;is it <ENTER>?
		cpfseq	char
		goto	cont07			;no, continue
		movlw	menu			;yes, display menu again
		call	strsend
		goto	loop			;go again
cont07	movlw	"0"				;is it '0'?
		cpfseq	numr
		goto	cont08			;no, continue
		;movlw	b'00000001'
		;xorwf	PORTB
		BTG	PORTB, 0
		movlw	string9
		call	strsend
		call	showb
		goto	loop			;go again
cont08	movlw	"2"				;is it '2'?
		cpfseq	numr
		goto	cont09			;no, continue
		;movlw	b'00000100'
		;xorwf	PORTA
		BTG	PORTA, 2
		movlw	stringa
		call	strsend
		call	showa
		goto	loop			;go again   [b]
cont09	movlw	"3"				;is it '3'?   
		cpfseq	numr
		goto	cont10			;no, continue
CheckA3		MOVLW	0x01
		CPFSEQ	temp2
		GOTO	CheckB3
		GOTO	PORTA3
CheckB3		MOVLW	0x02
		CPFSEQ	temp2
		goto	loop		; Tell them to select port Q[A/B]
PORTB3		BTG	PORTB, 3
		movlw	stringb
		goto	Contin3
PORTA3		BTG	PORTA, 3
		movlw	stringe
Contin3		
		call	strsend
		goto	loop			;go again [/b]
cont10	movlw	"5"				;is it '5'?
		cpfseq	numr
		goto	cont11			;no, continue
		;movlw	b'00100000'
		;xorwf	PORTB
		BTG	PORTB, 5
		movlw	stringc
		call	strsend
		call	showb
		goto	loop			;go again
cont11	movlw	"1"				;is it '1'?
		cpfseq	numr
		goto	cont12			;no, continue
		;movlw	b'00000010'
		;xorwf	PORTA
		BTG	PORTA, 1
		movlw	string5
		call	strsend
		call	showa
		goto	loop			;go again
cont12	movlw	"4"				;is it '4'?
		cpfseq	numr
		goto	cont13			;no, continue
		;movlw	b'00010000'
		;xorwf	PORTA
		BTG	PORTA, 4
		movlw	string6
		call	strsend
		call	showa
		goto	loop			;go again
cont13 movlw	"6"				;is it '6'?
		cpfseq	numr
		goto	cont14			;no, continue
		;movlw	b'01000000'
		;xorwf	PORTA	
		BTG	PORTA, 6
		movlw	string7
		call	strsend
		call	showa
		goto	loop			;go again
cont14	movlw	"7"				;is it '7'?
		cpfseq	numr
		goto	cont15			;no, continue
		;movlw	b'10000000'
		;xorwf	PORTA
		BTG	PORTA, 7
		movlw	string8
		call	strsend
		call	showa
cont15	goto	loop
;************************ [b]
;* Get Second char
showq	call	rs_recv			;wait for a char
		movwf	numr			;save as numeral
		andlw	b'01011111'		;convert to upper case
		movwf	char			;save as uppercase char
MyPortA	movlw	"A"				;is it 'A'?
		cpfseq	char
		goto	MyPortB			;no, continue
		MOVLW	0x01
		MOVWF	temp2
		return
;A2		call	showa
MyPortB	
		movlw	"B"				;is it 'B'?
		cpfseq	char
		goto	NoPort		;no, continue
		MOVLW	0x02
		MOVWF	temp2
		return
NoPort
		MOVLW	0x00
		MOVWF	temp2
		return
;     [/b]

;***********************
;* rs_send PORTA status
showa	movlw	pa_val			;send "PORTA = "
		call	strsend
		movlw	0x08			;set bitnum counter variable
		movwf	bitnum
		movff	PORTA,temp1		;save PORTA value in temp1
a_loop	rlcf	temp1			;rotate bit into carry
		bnc		a_30			;is the bit set?
		movlw	0x31			;yes, rs_send $31
		call	rs_send
		goto	a_bump
a_30	movlw	0x30			;rs_send $30
		call	rs_send
a_bump	decfsz	bitnum			;decrement counter
		goto	a_loop			;counter not zero, go again
		movlw	0x0d			;rs_send CR
		call	rs_send
		movlw	0x0a			;rs_send NL
		call	rs_send
		return

;***********************
;* rs_send PORTB status
showb	movlw	pb_val			;send "PORTB = "
		call	strsend
		movlw	0x08			;set counter
		movwf	bitnum
		movff	PORTB,temp1		;save PORTB value in temp1
b_loop	rlcf	temp1			;rotate next bit into position
		bnc		b_30			;is bit 7 set?
		movlw	0x31			;yes, rs_send $31
		call	rs_send
		goto	b_bump
b_30	movlw	0x30			;rs_send $30
		call	rs_send
b_bump	decfsz	bitnum			;decrement counter
		goto	b_loop			;counter not zero, go again
		movlw	0x0d			;rs_send CR
		call	rs_send
		movlw	0x0a			;rs_send NL
		call	rs_send
		return					;counter=0, done
		
;**************************************
;* send null-terminated string to rs232
;* pass string pointer in W
strsend	clrf	TBLPTRH			;set up table pointer
		movwf	TBLPTRL
strnext	tblrd	*+				;read table entry, post-increment
		movf	TABLAT,W		;get char in W
		bz		strdone			;is it 0?
		call	rs_send			;no, send it
		goto	strnext			;and get the next one
strdone	return					;yes it is 0, end of string

;******************************************
;* Wait for a char from RS232 - return in W
rs_recv	btfss	PIR1,RCIF		;wait for a byte from RS232
		goto	rs_recv
		movf	RCREG,W			;return received byte in W
		return

;*************************
;* Send char in W to RS232
rs_send	movwf	TXREG			;send byte in W 
sdloop	btfss	TXSTA,TRMT		;transmission done?
		goto	sdloop			;no, then wait some more
		return					;yes, done

;***************************
;* Bill BlueRoom's LED macro
LED		macro	x,y			;MACRO LED <PORTA>, <TRISA>
		movlw	x
		movwf	LATA		;LATA  = x
		movlw	y
		movwf	TRISA		;TRISA = y
		call	delay
		endm				;end macro       

;************
;* flash leds
flash	LED		b'00000001',b'10111110'	;LED <PORTA>, <TRISA>       
LED2	LED		b'01000000',b'10111110'	;LED <PORTA>, <TRISA>
LED3	LED		b'01000000',b'00111111'	;LED <PORTA>, <TRISA>
LED4	LED		b'10000000',b'00111111'	;LED <PORTA>, <TRISA>
LED5	LED		b'10000000',b'01111110'	;LED <PORTA>, <TRISA>
LED6	LED		b'00000001',b'01111110'	;LED <PORTA>, <TRISA>
		clrf	TRISA					;shut off leds
		clrf	LATA
        return 

;*******
;* Delay
delay   movlw   0x3c 
        movwf   loop1 
outer   movlw   0xc8 
        movwf   loop2 
inner   nop 
        nop 
        decfsz  loop2,F 
        goto    inner
        decfsz  loop1,F 
        goto    outer 
        return

;**************************
;* init RS232 at 9600,8,N,1
rs_init:
		movlw	0x0c			;0x0c=9600 baud
		movwf	SPBRG
		bcf		TXSTA,BRGH		;clear Baud Rate Select Bit (low speed)
		bcf		BAUDCTL,BRG16	;select 8-bit baud rate generator
		bcf		TXSTA,SYNC		;asynchronous mode
		bsf		RCSTA,SPEN		;enable serial port
		bsf		RCSTA,CREN		;enable async receive
		bsf		TXSTA,TXEN		;transmit enable
		return

		END
 
Last edited:
Found the PICkit2 as a learning tool link. From Xiaofan Chens site

http://mcuee.blogspot.com/search/label/USB

Wednesday, July 11, 2007

PICkit 2 as a USB Learning Tool

1. Brad Minch's Lab 2 HID example using gputils
**broken link removed**

2. PICKit 2 CDC emulation ported from Microchip's PICDEM FS USB
**broken link removed**

3. Mark Rages' PICKit 2 as a SPI Protocol Analyser Hack
**broken link removed**
The code is written in SDCC.
**broken link removed**

Posted by Xiaofan Chen at 8:59 AM 0 comments **broken link removed** Links to this post
Labels: PIC, PICKit, USB
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top