# Basic PIC Issues (16F88)

Status
Not open for further replies.

#### kannan.k

##### Junior Member level 2
16f88 porta digital outputs

Hi people.

I am working with the 8051 controller now and have started to learn the pic microcontroller. I Have a few issues and questions. The very first thing i am trying to do is to toggle a LED.

I am using
device 16F88
IDE MPLAB 7.10
OS win98
SW ICrprog 105D
HW multipicprogrammer from https://feng3.cool.ne.jp/en/pg5v2.html
guidance https://www.mikroelektronika.co.yu/english/index.htm

My code
Code:
;*****Set up the Constants****
;#include <p16f88.inc>

STATUS      equ       03h         ;Address of the STATUS register
TRISA       equ       85h         ;Address of the tristate register for port A
PORTA       equ       05h         ;Address of Port A
TRISB       equ       86h         ;Address of the tristate register for port B
PORTB       equ       06h         ;Address of Port B
COUNT1      equ       20h ;08     ;First counter address for our delay loops
COUNT2      equ       21h ;09     ;Second counter address for our delay loops

;****Set up the port****

bsf   	  STATUS,5   ;Switch to Bank 1
movlw     00h        ;Set the Port A pins
movwf     TRISA      ;to output.
movlw     00h        ;Set the Port B pins
movwf     TRISB      ;to output.
bcf       STATUS,5   ;Switch back to Bank 0

;****Turn the LED on****

Start      movlw      0ffh     ;Turn the LED on by first putting it
movwf      PORTA   ;into the w register and then on the port
movlw      0fh
movwf      PORTB

;lot of delay calls are here

;****Delay finished, now turn the LED off****

movlw      00h        ;Turn the LED off by first putting it
movwf      PORTA      ;into the w register and then on the port
movlw      00h
movwf      PORTB
;lot of delay calls are here

;****Now go back to the start of the program
goto       Start    ;go back to Start and turn LED on again

;****Here is our Subroutine

Delay

Loop1          decfsz        COUNT1,1     ;This second loop keeps the LED
goto          Loop1        ;turned off long enough for us to
decfsz        COUNT2,1     ;see it turned off
goto          Loop1        ;

return

;****End of the program****

end

My first question is that the porta does not give the proprer output (in the simulator) when
the movwf porta instruction is executed. any value upto 0x0f gives 00 and values greater that 10h shows up only as 10h in the port.... am i setting the trisa/b registers correctly?

My second question. The portb shows the correct value during simulation but when programmed and in the board it is is not working. I checked with my multimeter..... all the connections are ok.... and also i am sure the programmer is working fine.... programming and verification procedure does not give any errors.

While loading ICprog warns that the hex file does not contain a configuration and device ID information...

Thanks.

kannan.k

ok.... I again read the data sheet and found that the adc registers have to be modified for the port operation.....but still i am facing the issue with the hardware.

#### VVV

p16f88.inc

It seems to me you are missing the cconfiguration, so the PIC does not even start up, since the configuration tells it what oscillator to use, etc.

You must include at the top of your code
Code:
	__CONFIG    _CONFIG1, _CP_OFF & _CCP1_RB0 & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_IO
__CONFIG    _CONFIG2, _IESO_OFF & _FCMEN_OFF

These are straight from the template file, f88temp.asm, found in the Template\Code folder.
See what the significance of all those parameters is.
You can also set the bits manually in the programmer software, if you know what you are doing, but it is best to have all that info embedded in the hex file, so that it is there next time you need to program the micro and you don't have to enter it manually again.

### kannan.k

Points: 2

#### xjackal

##### Full Member level 3
pic _config1

hello.first of all ur led is inverse.imean u try to output but u dont need to 5v it.just ground it with .47k.it will be better.it will give u the chance it more.
u can edit ur adc by the reference table from pdf

;****Turn the LED on****

Start movlw 0ffh ;Turn the LED on by first putting it
this doesnt turn it on.there is a voltage from 5v and u make it also from cathode.please observe carefully.bye

#### Mike K8LH

##### Full Member level 2

Port A comes up as Analog inputs by default and you need to change them to Digital... Use bit names as defined in the 'include' file... You don't need to define equates like PORTA, PORTB, TRISA, etc.... These are already defined in the include file...

Good luck with your project... Regards, Mike
Code:
;******************************************************************

#include	<p16f88.inc>
errorlevel	-302

__CONFIG  _CONFIG1, _CCP1_RB0 & _LVP_OFF & _PWRTE_ON & _WDT_OFF & _HS_OSC
__CONFIG  _CONFIG2, _IESO_OFF & _FCMEN_OFF

;******************************************************************

org      h'0000'

RESET   clrf     STATUS          ;                              |B0
clrf     PORTA           ; clear Port A data latches    |B0
clrf     PORTB           ; clear Port B data latches    |B0
movlw    h'07'           ;                              |B0
movwf    CMCON           ; turn comparator off          |B0
bsf      STATUS,RP0      ; select bank 1                |B1
clrf     ANSEL           ; digital I/O, no ADC pins     |B1
clrf     TRISA           ; port A all outputs           |B1
clrf     TRISB           ; port B all outputs           |B1
bcf      STATUS,RP0      ; select bank 0                |B0
;

### kannan.k

Points: 2

#### kannan.k

##### Junior Member level 2
hardware checks for 16f88

Thanks for the help guys.

I set the ANSEL to zero and porta is ok (in the simulator). But there is still problem in the hardware. Looks like i have to include the configuration in the code itself.

regarding the LED...... well for the 8051 we use negative logic so that the controllers sink current rather the source it..... i believe it is the same for the PIC. In the specification it is give that direct LED drive is possible and a current of 25ma can be sinked.

looks like i should have learnt PIC before 8051 would have saved a lot of hair pulling

kannan.k

#### VVV

16f88 counter

The configuration should already be embedded in the .hex file since you added the __CONFIG directive. Can you double check the programmer actually takes into consideration those bits? If you are using MPLAB, just click on Configure...Configuration bits and the settings should all be there, just as you want them. The easiest to test are the HS oscillator and WDT off, for example.

It is the same logic for PIC, if the LED is connected between +5V and the I/O pin. But you can connect the LED to ground and drive it in positive logic, because the PIC pins can both sink and source high currents, unlike the 8051 pins.

By the way, I learned 8051 first and then the PIC. I still think the 8051 was not a bad concept, although it was rather slow. There are now versions that run 3 times as fast, though.

#### kannan.k

##### Junior Member level 2
p16f88 project

Hi

I have used the configuration as you people have pointed out, but i am yet to make the LED blink.

i am posting the code again....
Code:
        #include   <p16f88.inc>
errorlevel   -302

__CONFIG  _CONFIG1, _CCP1_RB0 & _LVP_OFF & _PWRTE_ON & _WDT_OFF & _XT_OSC
__CONFIG  _CONFIG2, _IESO_OFF & _FCMEN_OFF

org      h'0000'

RESET

clrf     STATUS
clrf     PORTA
clrf     PORTB
movlw    h'07'
movwf    CMCON
bsf      STATUS,RP0
clrf     ANSEL
clrf     TRISA
clrf     TRISB
bcf      STATUS,RP0

COUNT1      equ       20h
COUNT2      equ       21h

Start      movlw      00h
movwf      PORTA

call        Delay
call        Delay
call        Delay
call        Delay
call        Delay

movlw      02h
movwf      PORTA

call       Delay
call        Delay
call        Delay
call        Delay
call        Delay
goto       Start

Delay

Loop1	  decfsz     COUNT1,1
goto       Loop1
decfsz     COUNT2,1
goto       Loop1

return
end

It is really frustrating for me..... :-( I have been reading the datasheet for the past 3 days.

it would be great if these issues are cleared.

the program is working fine in the simulator.

I am using a 12 MHZ crystal so i will be using the _XT_OSC config word right?
and also am i using the correct configuration?

I have also noticed that when the pic is powerd ON the LED lights up for some time and then powers down..... if i am using 1 delay it stays on for about 5 seconds and if i use 5 delays it stays on for about 105 seconds. either way after powering down it does not come up again.

This might not be a structured method of debugging but i really dont have any option for now.

The MPLAB shows a checksum of 43E7 but ICProg shows a checksum of 43EA. Is there any error in this?

also i have not changed the hardware since the first post.

thanks.
kannan.k

#### UroBoros

à¹‚à¸„à¹‰à¸”16f88

Hai

I am not quiet femilier with this particualr PIC .But check these.

12Mhz crystal you must use HS oscillator.

All the best

### kannan.k

Points: 2

#### kannan.k

##### Junior Member level 2
16f88 digital port a

Thanks picstudent

I have been assuming that XT configuration has to be used..... when i changed it to HS the PIC worked perferctly.

Thanks all of you guys for helping me out!

well i DID learn quiet a few things for the past few days...... choose highspeed crysal oscillator when using above 4Mhz.

The ADC option has to be disabled to enable the digital IO

read the datasheet slowly and carefully

I will be working out other pheripherals of the pic in the next few days.....

Thanks

Status
Not open for further replies.