Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Problem of Driving Pin High in 16F1828

Status
Not open for further replies.

kahjoo

Junior Member level 2
Joined
Jul 23, 2012
Messages
21
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,456
Hi,

I in the middle of porting the MCU from 16F685 to 16F1828. Before transfer the old code to 18F1828, I've tried to run the MCU with the simple test program.
I'm using PICKit Eval board as to test the program. After program and run, found out the output pin of RC0 cannot drive the LED which only give about 1V output.

with the same code, change of config, I've run in 16F690 and there is no problem and LED able to be light up. Anything config that I miss out or wrong which I may overlook.

Below is original code of the 16F1828:-



#include <p16F1828.inc>
__CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_ON & _IESO_OFF & _FCMEN_OFF __CONFIG _CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_OFF & _BORV_19 & _LVP_OFF

cblock 0x20
Delay1 ;Define two file registers for the
Delay2 ; delay loop endc

org 0
Start
banksel TRISC
bcf TRISC,0 ; make IO Pin B.0 an output


movlw b'01101010' ;set osc
banksel OSCCON
movwf OSCCON ;configure OSCCON register


MainLoop
bsf PORTC,0 ; turn on LED C0

OndelayLoop
decfsz Delay1,f ; Waste time.
goto OndelayLoop ; The Inner loop takes 3 instructions per loop * 256 loopss = 768 instructions
decfsz Delay2,f ; The outer loop takes and additional 3 instructions per lap * 256 loops
goto OndelayLoop ; (768+3) * 256 = 197376 instructions / 1M instructions per second = 0.197 sec. ; call it a two-tenths of a second.

bcf PORTC,0 ; Turn off LED C0

OffDelayLoop
decfsz Delay1,f ; same delay as above goto OffDelayLoop
decfsz Delay2,f
goto OffDelayLoop
goto MainLoop ; Do it again...

end
 

Hi,

With these latest chips multifunction pins its easy to get things wrong when configuring them, however I think for PortC.0 its ok as you have done it, though it might be good practice to turn off the Analogue function in case you use any other Portc pins as Digital inputs.

Think your problem is that the ON delay is just 1ms and the OFF time 197ms, using the 4mhz osc you specify in Osccon - see Sim pictures.

Usually use this calculator for assembly delays.**broken link removed**


Edit, your code would not build because you missed off the ENDC to the CBLOCK directive

Code:
	cblock 0x20
	Delay1 ;Define two file registers for the
	Delay2 ; delay loop endc
	endc
 

Attachments

  • 2013-01-17 20_54_41-billyboy - MPLAB IDE v8.80 - Stopwatch.jpg
    2013-01-17 20_54_41-billyboy - MPLAB IDE v8.80 - Stopwatch.jpg
    65.5 KB · Views: 57
  • 2013-01-17 20_55_49-billyboy - MPLAB IDE v8.80 - Stopwatch.jpg
    2013-01-17 20_55_49-billyboy - MPLAB IDE v8.80 - Stopwatch.jpg
    64 KB · Views: 59

Hi,

Thanks. I've manage to trigger the output as required. Below is the modified code.



banksel OSCCON
movlw b'01101010' ;set osc
movwf OSCCON ;configure OSCCON register

BANKSEL PORTC
CLRF PORTC ;Init PORTC
BANKSEL LATC ;Data Latch
CLRF LATC
BANKSEL ANSELC
CLRF ANSELC ;Make RC<5:0> digital
BANKSEL TRISB
MOVLW b'00110000' ;Set RC<5:4> as inputs
;and RC<3:0> as outputs
MOVWF TRISC

banksel STATUS ;Back to Back 0

MainLoop


I've not look into detailed as I just want to test on the run. By the way, what compiler are you using as it's look new to me as I've never saw the tools with debug for the timer?

However, is that better way of switch back to bank0 when using "banksel" command?
Also, is that any way or good idea of making makro of the bank selection?

Thanks....
Kah Joo
 

That looks like the standard MPLAB stopwatch window to me.

'banksel' works in all cases but if you really have to optimize your code, there is a new instruction 'movlb x' which will directly select bank 'x' in a single step. I think MPLAB and MPLABX will automatically substitute movlb when you use the banksel directives, but obvioulsy only on the newer devices supporting that instruction, otherwise it sets/resets bits in the STATUS register instead.

Heed wp100's caution about multi-function pins, as you migrate to devices with more on-board peripherals it become important to select which the pin is internally connected to.

Brian.
 

Hi,

Thanks. I've manage to trigger the output as required. Below is the modified code.






I've not look into detailed as I just want to test on the run. By the way, what compiler are you using as it's look new to me as I've never saw the tools with debug for the timer?

However, is that better way of switch back to bank0 when using "banksel" command?
Also, is that any way or good idea of making makro of the bank selection?

Thanks....
Kah Joo


Hi,

You can use the movlb D'1' ; bank1 as Brian mentions but if you are using various 16Fs it might be more compatible to use the banksel directive.
To return to bank 0 just use ' banksel 0 ' - bansel 1 etc does not work, you must specify a register.

The pictures shown are of the stopwatch used in MPlabs SIM.

Build your code, goto Debugger, select tool, MPLABSIM then you can either RUN or Single Step though your code.

However for a long delay you really want to 'run' over it, so on your line of code Right click and Set a Breakpoint before and after the delay.

You then Start the STOPWATCH and set it to 4mhz , run to the first breakpoint, zero the stopwatch, Run to the second breakpoint to find your delay time.

You can do many other things using the Watch Windows to see how you code changes the system and user registers etc etc
 

Hi,

Thanks for the information. Will try it soon. Thanks again.

Kah Joo
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top