# Programme problem

Status
Not open for further replies.

#### Nick'

##### New Member
Code:
list	p=16F628A
include "p16f628a.inc"
__config _INTRC_OSC_NOCLKOUT & _PWRTE_ON & _BODEN_ON & _MCLRE_ON & _WDT_OFF & _CP_OFF
org	0x0000
movlw	0x07              ; I think these should also be added
movwf	CMCON
bsf STATUS,5
movlw 00h
movwf TRISA
bcf STATUS,5
movlw b'00000101'
movwf PORTA
goto $end Those were the codes i used in my PIC16F628A. I have connected the power supply of 5V,2A directly to the PIC as 5V is an ideal voltage. Then i connect the RA0, RA1 and RA2 to 3 leds (Directly connected to the pins without any resistors). However my led is not lighting up. Does anyone know why? Here is my second problem. I am using pickit2 and i would like to debug the code. I went to the debug and select my device(pickit2). I got an error, This is the screenshot. https://img196.imageshack.us/img196/5519/82348385.png #### Number17 ##### New Member You need to add a resistor with the LED's. You should also connect MCLR to +5v. The debugging problem I can't help you with, since I don't have a PICKIT 2. There is your prove that the code works. #### Attachments • ABCD0005.JPG 241.3 KB · Views: 162 #### Nick' ##### New Member Can you explain to me why i have to connect the 5V to the MCLR? Secondly, What resistor should i use (how many ohms)? Thirdly, are the output voltage of the PIC at RA0, RA1, RA2 are 5V equally? Last edited: #### Number17 ##### New Member Its simple. You defined it that way. __config _INTRC_OSC_NOCLKOUT & _PWRTE_ON & _BODEN_ON & _MCLRE_ON & _WDT_OFF & _CP_OFF If you don't want to connect mclr to +5v, or use it as a input then it should be like this: __config _INTRC_OSC_NOCLKOUT & _PWRTE_ON & _BODEN_ON & _MCLRE_OFF & _WDT_OFF & _CP_OFF Edit: I use anything I can find on my table. Between 270 - 1k works fine for me. But you can calculate the value using ohms law. I don't understand the last question. Last edited: #### be80be ##### Well-Known Member Code: list p=16F628A include "p16f628a.inc" __config _INTRC_OSC_NOCLKOUT & _PWRTE_ON & _BODEN_ON & _MCLRE_ON & _WDT_OFF & _CP_OFF org 0x0000 movlw 0x07 ; I think these should also be added movwf CMCON bsf STATUS,5 movlw 00h movwf TRISA bcf STATUS,5 movlw b'00000101' movwf PORTA goto$
end

Those were the codes i used in my PIC16F628A. I have connected the power supply of 5V,2A directly to the PIC as 5V is an ideal voltage. Then i connect the RA0, RA1 and RA2 to 3 leds (Directly connected to the pins without any resistors). However my led is not lighting up. Does anyone know why?

Here is my second problem. I am using pickit2 and i would like to debug the code. I went to the debug and select my device(pickit2). I got an error, This is the screenshot.
https://img196.imageshack.us/img196/5519/82348385.png

You can't debug a 16f628a with out special hardware.
If you want a chip to debug get some 16f88 they can be debugged with out any added hardware

This what you need # PIC16F627A*, 628A*, 648A*

Last edited:

#### AllVol

##### New Member
https://img196.imageshack.us/img196/5519/82348385.png [/URL]

You don't debugg using the PICkit 2. In Mslab you debug by selecting the 'debugger' heading, then 'select tool' then select '4 MSLAB SIM.

In the upper right hand corner a new toolbar will appear.

Go to view> watch. A new box will appear. Oh, gosh, this is getting complicated.

There are two sections to the box. On the right side, click on the down arrow, which will give you a whole list of the innards of the chip you are using. Scroll down until you find your variables, then, one by one highlight them and click. They will appear, seperately, in the heading. Click add.
'
Then, back under debugger, click on 'step into'.

Watch the screen where your program is and each time you click 'step into' you will see a bar on the left side step through each line of your program. At the same time, as each variable is acted upon, you will see change in the watch window.

Whew! That's as simple as I can make it. Hope you can follow.

NOTE: This procedure is only for debugging the program. It will not help you debug the hardware.

#### Nick'

##### New Member
Can you explain to me why i have to connect the 5V to the MCLR?

Secondly, What resistor should i use (how many ohms)?

Thirdly, are the output voltage of the PIC at RA0, RA1, RA2 are 5V equally?

Regarding my third question. All 3 pins will produce a 5V output. Am i correct? My input to the PIC (vdd) is 5V.

#### Number17

##### New Member
Regarding my third question. All 3 pins will produce a 5V output. Am i correct? My input to the PIC (vdd) is 5V.

5V, 25mA for each pin.

#### birdman0_o

##### Active Member
Use the resistors, it will save your uCs from the graveyard. Or the leds.
What project do you plan on making, or are you just messing around?

#### Nick'

##### New Member
Yes, i am just messing around. My major problem is i dont have a multimeter, so i cannot measure the current,A , hence not allowing me to calculate which resistor to be used. Given V = Ir, i have to know the current constant in order for me to calculate the resistance to produce 1.5v output for the LEDs.

#### AllVol

##### New Member
Yes, i am just messing around. My major problem is i dont have a multimeter, so i cannot measure the current,A , hence not allowing me to calculate which resistor to be used. Given V = Ir, i have to know the current constant in order for me to calculate the resistance to produce 1.5v output for the LEDs.

You can get a digital multimeter at Harbor Freight for around \$3 when they are on sale.

But for the problem you cite, you don't need one.

You know the voltage required - 1.5 V (more likely 2 V for red LED)
You should know that LEDs require less than 20 milliamps to operate
You know you have a 5 V supply

Therefore 5 V minus the 1.5 V for the LED equals ???
And that, divided by .020 amps equals ??? in ohms of resistance

#### Nick'

##### New Member
The resistor will decrease the voltage or current?

One more question is when i have a 5V supply through a 1.5V LED, will the LED use up the 1.5V, hence the voltage after the LED is 3.5V?

#### Number17

##### New Member
The resistor will decrease the voltage or current?

One more question is when i have a 5V supply through a 1.5V LED, will the LED use up the 1.5V, hence the voltage after the LED is 3.5V?

Do you have a basic electronic background? It seems useless to me to go directly to microcontrollers without basic knowledge.

Light Emitting Diodes (LEDs)

#### AllVol

##### New Member
The resistor will decrease the voltage or current?

One more question is when i have a 5V supply through a 1.5V LED, will the LED use up the 1.5V, hence the voltage after the LED is 3.5V?

You're getting the general idea.

I really strongly suggest you go to Welcome to Play-Hookey!
and let the man explain to you in words, diagrams, pictures and experiments, this facinating world of electronics.

Everything you want to know is explicitly given on that website.

Good luck!

#### blueroomelectronics

##### Well-Known Member
You don't debugg using the PICkit 2. In Mslab you debug by selecting the 'debugger' heading, then 'select tool' then select '4 MSLAB SIM.

Actually the PICkit2 is a pretty good debugger. But the 16F628A doesn't support debug. The 16F88 does though.

Last edited:

#### be80be

##### Well-Known Member
I said that on the first page
You can't debug a 16f628a with out special hardware.
If you want a chip to debug get some 16f88 they can be debugged with out any added hardware

This what you need # PIC16F627A*, 628A*, 648A*

Last edited:
Status
Not open for further replies.

Replies
11
Views
2K
Replies
0
Views
1K
Replies
1
Views
1K
Replies
6
Views
1K
Replies
0
Views
899