Well, I’ve given up (for the time being) on how to use my Macintosh to program the PIC controller. I took my lunch hour today at work to program my PIC p12F675 on the PICKit 1 Flash Starter Kit to blink its lights in a circular fashion. Since there is a lack of good info about this on the web, per my new initiative to inform the world (lol) I’m going to say exactly how I did it.
First, I installed the gnu pic utilities — of which I’m using gpasm to “assemble” my code into pic bytecode. (See below for the code.)
Next I compiled the code like this:
gpasm –dos -pp12F675 –hex-format inhx32 gp2.asm
It is necessary to add the –dos option since the upload program I use is a Windows program. Oh and by the way everything so far is Mac friendly. Now copy the resulting .hex file onto your windows box and upload it using the PICkit(tm) 1 FLASH Starter Kit application. I think I used the “Baseline Flash” instead of the “Classic” version. Control – I Imports, and Control – W writes.
Be sure you have the right kind of PIC — for my program I used a p12f675.
Voila!
Double click to replay if there is no controller.
Can’t see the video above? Click
here to download our video file, then launch it from your desktop.
Still can’t
see the video? Install Apple’s free QuickTime player.
Here is the code, for those at home who wish to duplicate my experiment.
1 ; This file is a basic code template for assembly code generation * 2 ; on the PICmicro PIC12F675. This file contains the basic code * 3 ; building blocks to build upon. * 4 ; * 5 ; If interrupts are not used all code presented between the ORG * 6 ; 0x004 directive and the label main can be removed. In addition * 7 ; the variable assignments for 'w_temp' and 'status_temp' can * 8 ; be removed. If the internal RC oscillator is not implemented * 9 ; then the first four instructions following the label 'main' can * 10 ; be removed. * 11 ; * 12 ; Refer to the MPASM User's Guide for additional information on * 13 ; features of the assembler (Document DS33014). * 14 ; * 15 ; Refer to the respective PICmicro data sheet for additional * 16 ; information on the instruction set. * 17 ; * 18 ;********************************************************************** 19 ; * 20 ; Filename: xxx.asm * 21 ; Date: * 22 ; File Version: * 23 ; * 24 ; Author: * 25 ; Company: * 26 ; * 27 ; * 28 ;********************************************************************** 29 ; * 30 ; Files required: * 31 ; * 32 ; * 33 ; * 34 ;********************************************************************** 35 ; * 36 ; Notes: * 37 ; * 38 ; * 39 ; * 40 ; * 41 ;********************************************************************** 42 43 list p=12f675 ; list directive to define processor 44 #include <p12f675.inc> ; processor specific variable definitions 45 46 errorlevel -302 ; suppress message 302 from list file 47 48 __CONFIG _CP_OFF & _CPD_OFF & _BODEN_OFF & _MCLRE_OFF & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT 49 50 ; '__CONFIG' directive is used to embed configuration word within .asm file. 51 ; The lables following the directive are located in the respective .inc file. 52 ; See data sheet for additional information on configuration word settings. 53 54 55 56 57 ;***** VARIABLE DEFINITIONS 58 w_temp EQU 0x20 ; variable used for context saving 59 status_temp EQU 0x21 ; variable used for context saving 60 mcount EQU 22h 61 ncount EQU 23h 62 new_tris EQU 24h 63 new_gpio EQU 25h 64 65 66 67 68 69 70 ;********************************************************************** 71 ORG 0x000 ; processor reset vector 72 goto main ; go to beginning of program 73 74 75 ; (no interrupt) ORG 0x004 ; interrupt vector location 76 ; (no interrupt) movwf w_temp ; save off current W register contents 77 ; (no interrupt) movf STATUS,w ; move status register into W register 78 ; (no interrupt) movwf status_temp ; save off contents of STATUS register 79 ; (no interrupt) 80 ; (no interrupt) 81 ; (no interrupt); isr code can go here or be located as a call subroutine elsewhere 82 ; (no interrupt) 83 ; (no interrupt) 84 ; (no interrupt) movf status_temp,w ; retrieve copy of STATUS register 85 ; (no interrupt) movwf STATUS ; restore pre-isr STATUS register contents 86 ; (no interrupt) swapf w_temp,f 87 ; (no interrupt) swapf w_temp,w ; restore pre-isr W register contents 88 ; (no interrupt) retfie ; return from interrupt 89 90 91 ; these first 4 instructions are not required if the internal oscillator is not used 92 main 93 call 0x3FF ; retrieve factory calibration value 94 bsf STATUS,RP0 ; set file register bank to 1 95 movwf OSCCAL ; update register with factory cal value 96 bcf STATUS,RP0 ; set file register bank to 0 97 98 99 ; remaining code goes here 100 101 bcf STATUS,RP0 ;Bank 0 102 clrf GPIO ;Init GPIO 103 movlw 07h ;Set GP<2:0> to 104 movwf CMCON ;digital IO 105 bsf STATUS,RP0 ;Bank 1 106 clrf ANSEL ;Digital I/O 107 movlw 08h ;Set GP<3:2> as inputs 108 movwf TRISIO ;and set GP<5:4,1:0> 109 ;as outputs 110 bcf STATUS,RP0 ;Bank 0 111 112 go 113 ; D0 114 bsf STATUS,RP0 ;Bank 1 115 movlw b'11001111' 116 movwf TRISIO ;and set GP<5:4,1:0> 117 bcf STATUS,RP0 ;Bank 0 118 movlw b'00010000' 119 movwf GPIO 120 call delay 121 ; D0 122 bsf STATUS,RP0 ;Bank 1 123 movlw b'11001111' 124 movwf TRISIO ;and set GP<5:4,1:0> 125 bcf STATUS,RP0 ;Bank 0 126 movlw b'00100000' 127 movwf GPIO 128 call delay 129 ; D0 130 bsf STATUS,RP0 ;Bank 1 131 movlw b'11101011' 132 movwf TRISIO ;and set GP<5:4,1:0> 133 bcf STATUS,RP0 ;Bank 0 134 movlw b'00010000' 135 movwf GPIO 136 call delay 137 ; D0 138 bsf STATUS,RP0 ;Bank 1 139 movlw b'11101011' 140 movwf TRISIO ;and set GP<5:4,1:0> 141 bcf STATUS,RP0 ;Bank 0 142 movlw b'00000100' 143 movwf GPIO 144 call delay 145 ; D7 146 bsf STATUS,RP0 ;Bank 1 147 movlw b'11111001' 148 movwf TRISIO ;and set GP<5:4,1:0> 149 bcf STATUS,RP0 ;Bank 0 150 movlw b'00000010' 151 movwf GPIO 152 call delay 153 ; D6 154 bsf STATUS,RP0 ;Bank 1 155 movlw b'11111001' 156 movwf TRISIO ;and set GP<5:4,1:0> 157 bcf STATUS,RP0 ;Bank 0 158 movlw b'00000100' 159 movwf GPIO 160 call delay 161 ; D5 162 bsf STATUS,RP0 ;Bank 1 163 movlw b'11011011' 164 movwf TRISIO ;and set GP<5:4,1:0> 165 bcf STATUS,RP0 ;Bank 0 166 movlw b'00000100' 167 movwf GPIO 168 call delay 169 ; D0 170 bsf STATUS,RP0 ;Bank 1 171 movlw b'11011011' 172 movwf TRISIO ;and set GP<5:4,1:0> 173 bcf STATUS,RP0 ;Bank 0 174 movlw b'00100000' 175 movwf GPIO 176 call delay 177 goto go 178 179 180 ;delay loop 181 delay movlw 0x4f 182 movwf mcount 183 loadn movlw 0xff 184 movwf ncount 185 repeat decfsz ncount,f 186 goto repeat 187 decfsz mcount,f 188 goto loadn 189 return 190 191 ; initialize eeprom locations 192 193 ORG 0x2100 194 DE 0x00, 0x01, 0x02, 0x03 195 196 197 END ; directive 'end of program' 198 199
Oh, were you wondering how I got the nice formatting for the code? I used VIM like this
:runtime! syntax/2html.vim
. Do :help 2html in VIM for more info.
3 replies on “Das Blinken Lights”
i would like to make a swimming distress alarm. which consistes of a transmitter and a receiner part.and i would like to do the programing in MCT language.can you help me.in my divice the transmitter part connected on the googel ,when the transmitter go inside the water and dont come back after 15 sec the transmitter will stop sending singnals and the reciver will produce some sound.if ypu have the same type program please sent me
thank you
Boby —
It sounds like you have an interesting project in mind. I don’t have a program that would do exactly what you want, but I can offer some suggestions.
First of all, I’d figure out how to make a sensor that can tell when it is under water. You might use conductivity or some optical sensor. I’d connect the output of the sensor to one of the inputs on the P12F675.
The P12F675 microcontroller is an eight-bit controller — so that means that it isn’t very easy for it to count higher than to 256. I would suggest that you set an interrupt to trigger once in a while. Every time it triggers, it should check that A/D converter to see if the sensor is under water. If it is under water then it should increment a counter. Then it should check the counter to see if it has been 15 seconds or longer. Since you can only count up to 256, don’t set the interrupt to any faster than 58.6 milliseconds. If it has been 15 seconds or longer, it should trigger the “alarm”.
The alarm transmission could use a circuit similar to the very simple one in this radio transmitter : http://www.scitoys.com/scitoys/scitoys/radio/computer/computer_controlled_transmitter.html
Good luck — I hope this helped.
I want to programme my PIC12F675 where the subroutines are written in some other page, saved as “.asm” and included in my source files.
When Iam doig so it is giving errors such as “expected end in subroutine”, it is also asking to define “programme related define.h” and “p12f675.inc” files even in subroutines.
************************************************ If any one from the groups knows the solution for this problem u please mail it to my email-id
“rakesh02_ie25@yahoo.com
*************************************************