Jump to content
pino

Problem For Pic16f628a

Recommended Posts

hi,

 

I'm new to the forum, I have a question.

 

I need to program the ports A and B as digital I / Os.

I am working with pic 16F628A, deputy program with the pic 16F84A works, but with f628a not going.

 

thanks for your attention.

 

I am Spanish and I wrote it with a translator, I hope is not too bad.

Share this post


Link to post
Share on other sites

The 628 has comparator (analogue) functions on RA0,1,2,3 pins which are enabled at POR. If you want digital I/O on these pins the you have to disable the camparator using the CMCON register.

 

Program the CMCON register = 0x07 to disable the comparator and make the pins digital. Set the TRISA and TRISB as normal for inputs or outputs.

 

Cheers

 

Reynard

Share this post


Link to post
Share on other sites

Pino,

 

I need to program the ports A and B as digital I / Os.

I am working with pic 16F628A, deputy program with the pic 16F84A works, but with f628a not going.

This kind of problem is due to the fact that some of the ports have analogue functions and these functions are enabled by default.

Add code cmcon = 0x07; to your program. Have a look at the data sheet for more information.

 

Regards

Dave

Share this post


Link to post
Share on other sites

thanks for your answers.

 

I have thought better and I have first tested the program with the PIC16F84 and I do not work.

 

the problem comes because I want to use the display mode 4bits to save pins.

 

I work in 8bit mode, and I recovered a program of your page to make it work 4b i no way it will work.

 

the program works, but no message comes in, leaving symbols

 

have if I echo something wrong !!!!!

 

thanks for all, then the program

 

 

 

dim dato as byte

dim cont as byte

dim cadena as string(38)

dim j as byte

dim cadena2 as string(15)

dim puls1 as bit

dim puls2 as byte

dim est as byte

dim est2 as byte

dim est3 as byte

dim est4 as byte

dim savep2 as byte

dim savep3 as byte

 

 

 

 

Sub main()

 

'cmcon = 7

 

trisa =0x18 'configuro porta 3 y 4 como entrada

trisb =0x00

 

 

call delay_s (1)

 

call lcd_init()

'porta.1=1

 

call lcd_clear() 'BORRAR DISPLAY

 

call lcd_putcmd(0x38)

call lcd_line1()

 

cadena = "EME sound 40w Sound Amplifier 1.0" '34

 

for j=0 to 34 step 1

 

dato = cadena(j)

 

call lcd_putch(dato)

 

next j

 

puls1=0

puls2=0

 

call delay_s (1)

 

for j=0 to 21 step 1 'desplaçament a l'esquerra

 

call lcd_putcmd(0x18)

 

call delay_ms (255)

 

next j

'...........................................................

call lcd_clear() 'BORRAR DISPLAY

'...........................................................

ini:

if puls1=1 then

puls2=savep2

call primera ()

savep2=puls2

else

'segunda linea display

puls2=savep3

call segunda ()

savep3=puls2

 

end if

goto ini

end sub

 

sub primera()

 

call lcd_putcmd(0x38 ) 'posiciono texto al principio

call lcd_line1() 'posiciono texto en la primera linea

 

call compro(puls1, puls2) 'compruebo si he pulsado

 

'...........................................................

 

if puls1=0 then

Select Case est4

Case 0

cadena="AMPLIFICADOR OFF"

 

Case 1

cadena="AMPLIFICADOR ON"

 

End Select

 

else

est=puls2&1

 

Select Case est

Case 0

cadena="AMPLIFICADOR<OFF"

est4=0

 

Case 1

cadena="AMPLIFICADOR< ON"

est4=1

End Select

end if

'...........................................................

'en la posicion 92 es donde puedo situar el cursor

 

'...........................................................

for j=0 to 15 step 1

 

dato = cadena(j)

 

call lcd_putch (dato)

 

next j

 

end sub

 

sub segunda()

 

call lcd_putcmd(0x38 ) 'posiciono texto al principio

call lcd_line2() 'posiciono texto en la segunda linea

 

call compro(puls1,puls2) 'compruebo si he pulsado

 

'...........................................................

 

if puls1=1 then

Select Case est3

Case 0

cadena2="VENTILACION OFF"

 

Case 1

cadena2="VENTILACION MIN"

 

Case 2

cadena2="VENTILACION MED"

 

Case 3

cadena2="VENTILACION MAX"

End Select

else

est2=puls2&3

Select Case est2

Case 0

cadena2="VENTILACION <OFF"

est3=0

Case 1

cadena2="VENTILACION <MIN"

est3=1

Case 2

cadena2="VENTILACION <MED"

est3=2

Case 3

cadena2="VENTILACION <MAX"

est3=3

End Select

end if

'...........................................................

'paso los valores al LCD

for j=0 to 15 step 1

 

dato = cadena2(j)

 

call lcd_putch (dato)

 

next j

'...........................................................

 

 

 

end sub

 

'******************************************************************

'subrutina de comprobacion por si se a pulsado el algun pulsador

sub compro( byref puls1 as byte, byref puls2 as byte)

 

 

if porta.4=0 then

call delay_us(100) 'delay antirrebote

if porta.4=0 then

puls1=puls1+1

call delay_us(100) 'delay antirrebote

end if

end if

'----------------------

'espero que acabe de pulsar el boton

espera2:

if porta.4=0 then

goto espera2

end if

'--------------------------------------------------------------

if porta.3=0 then

call delay_us(100) 'delay antirrebote

if porta.3=0 then

puls2=puls2+1

call delay_us(100) 'delay antirrebote

end if

end if

'---------------------

'espero que acabe de pulsar el boton

espera:

if porta.3=0 then

goto espera

end if

 

end sub

 

'********************************************************

'* *

'* LCD 16x2 LIBRARY FOR USE WITH BOOST BASIC *

'* *

'* WRITTEN BY : PUNERJOT SINGH MANGAT *

'* COUNTRY : INDIA *

'* CITY : PATIALA *

'* WEB PAGE : www.rackeys.com/punerjot *

'* EMAIL : punerjot@rackeys.com *

'* SOURCEBOOST ID : c58_4311 *

'* RELEASE DATE : March 03, 2006 *

'* REVISED DATE : May 24, 2006 *

'* *

'********************************************************

'

'

'

' commandas are

' lcd_putch(ASCII value of char to be printed)

' lcd_clear()

' lcd_line1()

' lcd_line2()

' lcd_init()

'

' any 16x2 alphanumeric lcd can be used as far as it uses hd44780 compatible chipset

'

' Pin connections of pic16f877A to lcd

' PIC PINS LCD PINS

' -------- --------

' RB2 6

' RB3 4

' RB4 11

' RB5 12

' RB6 13

' RB7 14

' 1 gnd

' 2 +5V

' 3 contrast (typicaly connected to gnd via 2.2 k resistor)

' 5 +5V

'

'

' RB0 and RB1 of this PORTB are free

'

'

 

 

'******************************* delay routines for the LCD **************************

sub wait_us()

DIM wait_count as byte

asm

{

MOVLW d'45'

MOVWF _wait_count

LOOP_LCD:

DECFSZ _wait_count, F

GOTO LOOP_LCD

return

}

end sub

'******************************* delay routines for the LCD ends **************************

 

 

 

 

sub lcd_strobe()

porta.2 = 1 'E

porta.2 = 0

end sub

 

 

 

sub lcd_byte(dato as byte)

portb = (portb & 0x0f)

portb = (portb | (dato & 0xf0))

call lcd_strobe()

portb = (portb & 0x0f)

portb = (portb | (dato << 4))

call lcd_strobe()

 

if porta.0=1 then

call delay_10us(4) 'ret 40uS

call wait_us()

else

call delay_100us(19) 'ret 1.64mS

end if

 

 

 

end sub

 

 

 

'************************ Procedure to output char to lcd *****************************

sub lcd_putch(dato as byte)

porta.0 = 1 'pin 3 of prt b as high RS

call lcd_byte(dato)

end sub

 

 

 

'************************ Procedure to give commands to lcd *****************************

sub lcd_putcmd(c as byte)

porta.0 = 0

call lcd_byte©

end sub

 

 

 

'************************ LCD Initializing routines *****************************

sub lcd_init()

trisb = ( 00000000b ) 'pin(0) and pin(1) of this PORTB are free so it can be used for RS232

porta.0 = 0

call delay_ms(50)

portb = (portb & 0x0f)

portb = (portb | 0x30)

call lcd_strobe()

call delay_ms(5)

call lcd_strobe()

call wait_us()

call lcd_strobe()

call delay_ms(5)

portb = (portb & 0x0f)

portb = (portb | 0x20)

call lcd_strobe()

call wait_us()

call lcd_putcmd(0x28)

call lcd_putcmd(0x08)

call lcd_putcmd(0x0C)

call lcd_putcmd(0x06)

end sub

 

 

 

'************************ Procedure to clear the lcd *****************************

sub lcd_clear()

call lcd_putcmd(0x01)

call delay_ms(2)

end sub

 

 

 

'******************** Procedure to goto the begning of line1 of the lcd *****************

sub lcd_line1()

call lcd_putcmd(0x80) 'start of first line

end sub

 

 

 

'******************** Procedure to goto the begning of line2 of the lcd *****************

sub lcd_line2()

call lcd_putcmd(0xc0) 'start of second line

end sub

Share this post


Link to post
Share on other sites

hello, I have a problem, I echo a project 16F84A pic, and an LCD.

 

with LCD monitors the status of a relay and an outlet controlled by PWM.

 

the problem is if i leave the program just as I have it and it works, I have available for the relay outputs and PWM.

 

I then opted for two exits,

1. put 4bits LCD mode, is more logical because I have so ja routines for any project.

2. use a 16F628A, the problem is not going to pick up the program. but good

 

and opted for the first i and then I'll manage to operate on a 16F628A.

 

BELOW you herewith the basic program with the configuration of the LCD 8bits, which is what works.

 

after the i-mode LCD 4bits which is what I do not work, because I get strange symbols, have been going for more but I do reconxolis nose that bad.

 

if you can make a will you do me a favor look thank you very much everybody.

Share this post


Link to post
Share on other sites

Your content will need to be approved by a moderator

Guest
You are commenting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoticons maximum are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×