Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
April 25, 2024, 09:47:14 09:47


Login with username, password and session length


Pages: [1]
Print
Author Topic: Help on pic16f628a...  (Read 5438 times)
0 Members and 1 Guest are viewing this topic.
MicroBox
Junior Member
**
Offline Offline

Posts: 35

Thank You
-Given: 11
-Receive: 0


« on: October 23, 2008, 01:51:01 13:51 »

Hello everyone,
                    Can anyone share a code in using Picbasicpro v.2.50 using pic16f628a to turn on Led1 and Led2 in portB.4 and portb.5 using internal clock. And to trigger the Led1 and Led2 I would press 1 or 2 to the hyperterminal commanding my pic to lit the leds and I want to use the internal usart.

here is a code I found but not working...

Include "modedefs.bas"
CMCON=%00000111
DEFINE OSC 4

DEFINE HSER_RCSTA 90h
'DEFINE HSER_TXSTA 24h '9600 baud rate, BRGH=1
DEFINE HSER_BAUD 9600
DEFINE HSER_SPBRG 129 '25 for 4MHz
DEFINE HSER_CLROERR 1 


Cnt VAR word ' Cnt is a word variable
inputData var word ' variable to receive data into

' START OF MAIN PROGRAM
'
CMCON = 7 ' RA0-RA3 are digital I/O
TRISA = 0 ' PORT A is output
PortB = 0
TRISB = %11111101 ' RB1 is Input others output

cnt = 0
main:

Hserin [inputData]

cnt = inputData

if Cnt = 1 then high PortB.4
pause 1000
goto main

END ' End of program


thanks in advance.
« Last Edit: October 23, 2008, 01:51:52 13:51 by MicroBox » Logged
Jagi
Newbie
*
Offline Offline

Posts: 27

Thank You
-Given: 26
-Receive: 12


« Reply #1 on: January 23, 2009, 05:36:53 17:36 »

Hello everyone,
                    Can anyone share a code in using Picbasicpro v.2.50 using pic16f628a to turn on Led1 and Led2 in portB.4 and portb.5 using internal clock. And to trigger the Led1 and Led2 I would press 1 or 2 to the hyperterminal commanding my pic to lit the leds and I want to use the internal usart.
here is a code I found but not working...
----deleted some of the code you wrote.....

Hserin [inputData]

cnt = inputData

if Cnt = 1 then high PortB.4
pause 1000
goto main

What are you trying to achieve here? And what do you mean by "not working" Huh  From the code it looks like when Cnt=1 you turn on PortB.4, which is okay. Now what happens when Cnt takes the values 0, 2, 3,.....? You have not told the micro what to do?

I would expect the code to be something like this after you get data from the USART (check the syntax with the compiler, I have not used Basic in the past 10 years!!)

if Cnt = 1 then
        high PortB.4     //turn on port B pin 4
        low  PortB.5     //turn off port B pin 5
else if Cnt = 2 then
        low PortB.4      //turn off port B pin 4
        high PortB.5     //turn on port B pin 5
else                        //any other value
        low PortB.4      //turn off both pins port B 4 and 5
        low PortB.5
endif
Logged
ero
Junior Member
**
Offline Offline

Posts: 43

Thank You
-Given: 12
-Receive: 27


« Reply #2 on: January 23, 2009, 07:32:25 19:32 »

It was not so clear what do you want to do. For this reason I decided to write program as follows;
- when you press 1 on the PC keyboard the LED-1 will be on first time. If you press again 1 the led1 will be off.
- Same as the first item if you press 2 theled-2 will be on and if you press again it will be off.

You can simulate it also in proteus by making the followings;
- Connect one led over 330 ohm resistance to PortB.4 (LED-1)
- Connect another led over 330 Ohm resistance to PortB.5 (Led-2)
- Place the Virtual Terminal to the screen and connect TX pin of Virtual terminal to PortB.1 which is the RX pin of Hardware Usart.
Thats all.

As you have seen in the program I used Usart Interrupt which is the best way for this kind of programs.

Ero  (ETE)

****************************************************************
'*  Name    : microbox.BAS                                      *
'*  Author  : [                   E.T.E.                      ] *
'*  Notice  : Copyright (c) 2009  )        *
'*          : All Rights Reserved                               *
'*  Date    : 23.01.2009                                        *
'*  Version : 1.0                                               *
'*  Notes   :                                                   *
'*          :                                                   *
'****************************************************************
'Can anyone share a code in using Picbasicpro v.2.50 using pic16f628a
'to turn on Led1 and Led2 in portB.4 and portb.5 using internal clock.
'And to trigger the Led1 and Led2 I would press 1 or 2 to the hyperterminal
'commanding my pic to lit the leds and I want to use the internal usart.
 
@ DEVICE PIC16F628A
@ DEVICE PIC16F628A, WDT_ON
@ DEVICE PIC16F628A, PWRT_ON
@ DEVICE PIC16F628A, BOD_ON
@ DEVICE PIC16F628A, PROTECT_OFF
@ DEVICE PIC16F628A, LVP_OFF
@ DEVICE PIC16F628A, CPD_OFF
@ DEVICE PIC16F628A, INTRC_OSC_NOCLKOUT
'---------------------------INPUT-OUTPUT ARRANGEMENT----------------------------
PORTA=0:TRISA=%00000000
PORTB=0:TRISB=%00000010 'PORTB.1 is input all others are output.
CMCON=7

'-------------------COMUNICATION DEFINES----------------------------------------
DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
DEFINE HSER_SPBRG 25  ' 9600 Baud @ 0,16%
DEFINE HSER_CLROERR 1 ' Clear overflow automatically

'-------------------------VARIABLES---------------------------------------------
Cnt       VAR BYTE 50' Cnt is a word variable
inputData var Byte 51' variable to receive data into
TEMP      var BYTE 52

SYMBOL GIE  =INTCON.7   'genel interruptları aƧıyor
SYMBOL PEIE =INTCON.6   'peripheralinterruptları aƧıyor
SYMBOL RCIE =PIE1.5     'USART Recive interrupt enable bit
SYMBOL RCIF =PIR1.5     'USART Receive interrupt flag bit
symbol led1=PORTB.4
SYMBOL Led2=PORTB.5
'---------------------------INITIALISATION--------------------------------------
RCIE=1
PEIE=1
GIE=1
INTCON=%11000000
ON INTERRUPT GOTO INT

START:
      IF Cnt=49 then
          led1=1-led1
          pause 100
          cnt=0
      endif   

      if cnt=50 then
        led2=1-led2
        pause 100
        cnt=0
      endif
      goto start
     
DISABLE
INT:
    GIE=0
    hSerIn , [INPUTDATA] 
    Cnt=inputdata
    TEMP=RCREG
    GIE=1
    Resume
enable

END
Logged
Jagi
Newbie
*
Offline Offline

Posts: 27

Thank You
-Given: 26
-Receive: 12


« Reply #3 on: January 24, 2009, 03:14:20 15:14 »

ero, you are right, MicroBox did not give us a clear specification as to what he wants to achieve. I see a lot of people who are asking questions do not know what they want. They just post some vague question and wait for us to figure out a solution for them Cry
I appreciate the effort you put into making a working sample code that is usable. Smiley
Logged
pickit2
Moderator
Hero Member
*****
Offline Offline

Posts: 4646

Thank You
-Given: 826
-Receive: 4207


There is no evidence that I muted SoNsIvRi


« Reply #4 on: January 24, 2009, 05:55:48 17:55 »

I think if you read the users other post, and note date of posts, He is just asking questions, and not wanting and / or waiting for answers.
Logged

Note: I stoped Muteing bad members OK I now put thier account in sleep mode
bbarney
Moderator
Hero Member
*****
Offline Offline

Posts: 2430

Thank You
-Given: 405
-Receive: 545


Uhm? where did pickit put my mute button


« Reply #5 on: January 24, 2009, 08:16:34 20:16 »

Actually the OP hasn't been here in a 1 1/2 month's so this locked
Logged

Ever wonder why Kamikaze pilot's wore helmet's ?
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC