I'm using an old MELabs USB Programmer and melabs Programmer V 4.51 beta software. I have NOT write protected the 16F819 chip. I have it configured such:
osc = INTRC
WDT = enabled
Power up timer = Enabled
MCLR pin funct = input pin
Brownout reset = Enabled
Low voltage programming = Disabled
CCP multiplex = RB2
Flash prog mem write enable = All
code = Not Protected
Data EEPROM = Not Protected
Here is my code:
Code:
INCLUDE "modedefs.bas"
define osc 4
osccon= %01100000
DEFINE ADC_BITS 8 'this sets number of a/d bits, using 10 gives much higher resolution
DEFINE ADC_CLOCK 2 'choose clock source for a/d, 2 gives a stable reading
DEFINE ADC_SAMPLEUS 50 'sample wait time 50 microseconds
'LCD declarations-------------
CR CON 13 'carriage return
LF CON 10 'cursor down one line keeps horiz position
crsrH CON 1 'home cursor
bell CON 7 'beep
clrlcd CON 12 'clear the lcd
poscmd CON 16 'position cursor
N9600 CON $4054 'value for 9600 baud setting
PORTA = 0
PAUSE 1
PORTB = 0
PAUSE 1
trisa = %11000001
trisb = %00000000
ADCON1 = %00001110
commpin VAR porta.4 'serial pin to LCD
Button1 var porta.1
MuxOutput var byte
SwSelect var byte
SwSelect = 8
pause 1000
GoSub kls
SerOut2 commpin,n9600,[CLRLCD,bell]
pause 100
mainloop:
end 'NEVER use "end"!!!! it destroys the chip!
portb = swselect
adcin 0,muxoutput
gosub lcdtext
gosub SelectSwitch
gosub button1NOTpressed
goto mainloop
SelectSwitch:
Swselect=swselect + 1
if swselect = 16 then
swselect = 8
endif
return
lcdtext:
SerOut2 commpin,n9600,[crsrh,"T",dec (portb-7),"=",dec muxoutput," REQ=",bin portb," "]
SerOut2 commpin,n9600,[" ",lf]
return
button1NOTpressed:
adcin 0,muxoutput
gosub lcdtext
IF button1 = 1 Then
GoTo button1NOTpressed 'hold here until button released
EndIF
gosub button1pressed
Return
button1pressed:
IF button1 = 0 Then
GoTo button1pressed 'hold here until button released
EndIF
Return
'Clears LCD screen --------------
KLS:
SerOut2 commpin,n9600,[clrlcd]
Return
beep:
SerOut2 commpin,n9600,[bell] 'tech 8 beep
Return
End
After programming the chip, it never programs again. All I get when trying to reprogram is the error message "Target Device does not match selected device".
Bookmarks