Quantcast
Channel: MEL PICBASIC Forum
Viewing all 4743 articles
Browse latest View live

Hserout3, hserout4, ...

$
0
0
What might be the reason or the reasons for PBP developers not to write Hser commands for 3,4,5 ?

Hserout3,Hserout4,Hserout5 ?
or Hserinx ?

Nextion Touchscreen LCD User Interface

$
0
0
Recently I tried the Nextion 7" and 3.2" touch screen LCDs.

They have a simple, not well documented, IDE that is hard to learn because you rely on YouTube tutorial videos of other users.

The LCDs have internal controller that does good job on taking the load off the MCU and almost work on its own.

I 'll post what I have done without any PIC connected yet.

I am very impressed of these relatively cheap devices that make good user interface without much load on the controller chip, without real buttons and having good graphics like bars, gauges numeric displays or impressive backgounds.

I need more info on how to setup the communication or the settings of the LCD since I could not find a pdf Manual yet.

Spent days to find out that the if (.....) command should not have a space after the if and had to rely on my observation that every one did not put a space there.

Anyway, is a very interesting interface to PIC's

Ioannis

18F4680 Internal Oscillator

$
0
0
I am working with the 18F4680 and for some reason can't get the internal oscillator to work. The external works fine.
I may need to also configure config1H, but it seems everything I did to try that would result in a compile error message. Is there something else I am missing?

I tried the below and it resulted in compiler error
#CONFIG
_CONFIG _OSC_IRCIO67_1H
#ENDCONFIG



I edited the PIC18F4680.PBPINC by changing the #CONFIG section from CONFIG OSC = HS to CONFIG OSC = IRCIO67. This did compile with no error, but also wouldn't run.


This is the code which I think should work.


OSCCON = $72 ' Set internal 8Mhz OSC
'OSCCON = %11100010 ' Set internal 4Mhz OSC
#Config
CONFIG OSC = IRCIO67 ;Sets for internal oscillator
#endconfig


DEFINE OSC 8 'Sets Osc to 8MHZ




'Setup
ADCON0 = $00 'Disables A/D module
ADCON1 = $0F 'Sets inputs to digital
CMCON = $07 'Takes pins D<3:0> to digital from default PW mode

PIC in ARCNET

$
0
0
Has anyone used one of these devices in an ARCNET network? Yes, arcnet is old but I hear it is making a comeback and you get a free 8 track of Bee Gees when you order the hardware. Anyway, GE Medical used arcnet within most of their older medical equipment which is still around. I've used a USB22 device from Contemporary Controls and created Windows based software for communicating to the system. One of my projects is to take this Windows based software and put it into a microcontroller. At the moment my plan is to use the 18F4680 in part because it has UART and CAN. The arcnet controller is a COM20020i and the network driver is an HYC9088 for coax. I have the schematics for the GE system which can be used as a reference design. I also found a reference design online, but it was a Heathkit/Zenith board. Based upon a quick review, it seems that the pic will interface using an 8 bit data bus and either a multiplexed address bus or a separate 3 bit address bus. Set some registers, then read and write the data. The data packets I need to communicate are fairly simple. Let me know if anyone has any experience with such networks.
thanks

Morse Code Bot

$
0
0
Hi Guys :)

Here’s a video which shows the crux of a project to use a custom pic controlled TENS unit to contract my muscles
through the use of electrodes, to make my hand key some predefined, valid Morse code:



There are a couple of other videos on my channel prior to this, of the same series that better explain the background of the project.
This one is jus the crux of it containing the best demo so far.

18F45K40 Can't set PORTD.1

$
0
0
For 18F45K40, I can not set PORTD.1

LATD.1 = 1 does not work.
PORTD.1 = 1 does not work.
HIGH PORTD.1 does not work.
HIGH LATD.1 does not work.
ASM does not work.

But if I use another compiler it works.

So where does it come from?

MQ 135 sensor

$
0
0
i have a MQ135 air quality sensor connected to a 18F2450 and I am able to get analog readings from it. I am interested in the CO2 readings, but looking at the datasheet it appears that to go from an analog reading to a parts-per-million equivalent involves some logarithmic math. Does anyone have any suggestions for getting around this? I would settle for something that provided an approximation.

Glitches when changing portD seen on other ports

$
0
0
Hello
I am using portD as a data port, 4 bits of portA as an address bus, and porte as the chip select, data strobe and direction bits. When the data switch from 3F to 40, 7F to 80, and BF to C0 there is a glitch. The data bus shows a few values before settling, but what is odd is the address bus, which isn't being changed or written to in any way also sees a glitch then settles back to the address it should have and likewise I get a 4ns pulse on the Chip Select and Data Strobe bits.

#Config
CONFIG OSC = HS ;Sets for external oscillator HS = external oscillator high speed Internal = IRCIO67
#endconfig


DEFINE OSC 20 'Sets Osc to 20MHZ

'Setup
ADCON0 = $00 'Disables A/D module
ADCON1 = $0F 'Sets inputs to digital
CMCON = $07 'Takes pins D<3:0> to digital from default PW mode
CCP1CON = $00
ECCP1CON = $00
INTCON = %00111111

define HSER_BAUD 38400
DEFINE NO_CLRWDT 1

Do until x = Length
'Set data bus
LATD = X
'Set the direction
PORTE.2 = 0
'Select the chip
PORTE.0 = 0
'Strobe the data
PORTE.1 = 0
'Disable strobe 'At 8mhz this is active for 1uS at 20mhz this is active for 400nS
PORTE.1 = 1
PORTE.0 = 1
PORTE.2 = 1
x = x + 1
loop




Attachment 8932
Attached Images
 

Nokia and hserin question

$
0
0
Hi to all

reading about the nokia lcd projects i´m trying to learn a little bit more about this devices, my goal is try to get hserin commands and display on this lcd however i need to capture serial data and display on hex format, but really i can´t understand how to did, in normal 2x16 lcd whit (HEX2) you can do this but reading some examples about nokia to get chars are using (DIG),agree whit this post http://www.picbasic.co.uk/forum/showthread.php?t=24078 i can see that maybe is more a little hard for implementation. I appreciate any help or advice about this issue.

Thanks very much for any reply about this

4x MAX7219 dot matrix modules, daisy chained, usable with PBP

$
0
0
Hello, there are a lot of modules, containing 4x MAX7219, which are daisy chained, and each of them drives 8x8 led matrix, like this: https://www.ebay.com/itm/MAX7219-Blue-led-matrix-MCU-control-LED-Display-module-for-Arduino-Raspbe-JBM/264335324017

I want to drive them with PBP, and as I learned from this app note: https://www.maximintegrated.com/en/app-notes/index.mvp/id/3947 when they are daisy chained with all pins, I have to send complete set of data in sequence. I mean, first I send data for 1st module (whole batch, including brightness, decode mode, etc) and when I send it again, 2nd module receives it, then 3rd module and so on, correct?


Interrupt issue with PIC16F18877 and DT-Ints...

$
0
0
Hello everyone,

I have a board that uses a PIC16F18877 to check the states of 16 inputs using IOC interrupts. Once one of the interrupts are triggered, I set a corresponding flag that is checked in the main loop. If the flag is set, I set 1 of 16 outputs until a user defined counter has reached its predetermined value, then I clear the flag and clear the output. This stage works well.

Included in with my interrupts in a separate handler, I toggle an LED for my heart beat.

My issue is that when I start the heart beat interrupt, sometimes the PIC will freeze and sometimes it doesn't. More often then not, the PIC will freeze with my heart beat LED always on.
I would appreciate a second pair of eyes to look over this short bit of code and point out what I may be doing wrong.

Code:

;*******************************************************************************
; Defines section.
;*******************************************************************************
    DEFINE OSC 32          ; Oscillator set to 32Mhz set by Config1 above.
;*******************************************************************************
; Timer 1 control registers.
;*******************************************************************************
    T1CON  = %00110110    ; Prescaler=8, Do not Synch, TMR1 OFF.
    T1GCON  = %00000000    ; Timer 1 Gate disabled.
    T1CLK  = %00000101    ; MFINTOSC Selected for Timer 1 clock source.


    PIR4.0 = 0
    TMR1L = $0A
    TMR1H = 0
;*******************************************************************************
; Interrupt control registers.    Not used.
;*******************************************************************************
    INTCON  = %11000000    ;
'    PIE0    = %00000000    ;
'    PIE1    = %00000000    ; 
'    PIE2    = %00000000    ;
'    PIE3    = %00000000    ;
    PIE4    = %00000001    ;
'    PIE5    = %00000000    ;
'    PIE6    = %00000000    ;
'    PIE7    = %00000000    ;
'    PIE8    = %00000000    ;
;*******************************************************************************
; Interrupt On Change for ports with IOC.  Ports A,B and C only apply. 
; 1 = enabled, 0 = diabled.
;*******************************************************************************
    IOCAF = %00000000      ; Interrupt-on-Change PORTA flags.
    IOCAP = %11111111      ; Interrupt-on-Change PORTA Positive Edge Enable bits.
    IOCAN = %00000000      ; Interrupt-on-Change PORTA Negative Edge Enable bits.
   
    IOCBF = %00000000      ; Interrupt-on-Change PORTB flags.
    IOCBP = %11111111      ; Interrupt-on-Change PORTB Positive Edge Enable bits.
    IOCBN = %00000000      ; Interrupt-on-Change PORTB Negative Edge Enable bits.
;*******************************************************************************
;ASM INTERRUPTS COURTESY OF DARREL TAYLOR.       
;*******************************************************************************
    ASM
INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
        INT_Handler  TMR1_INT,        _ToggleLED1,  PBP,  yes
        INT_Handler  IOC_INT,          _RelaySense,  PBP,  yes


    endm
    INT_CREATE              ; Creates the interrupt processor
    ENDASM


    PAUSE 500
    goto Start
;*******************************************************************************
; INTERRUPT SERVICE ROUTINES START HERE.
;*******************************************************************************
; IOC interrupt handler checks which interrupt flag has been set for PORTA and
; PORTB.  Each flag bit corresponds to an output. Example: IF IOCAF.1 is set,
; then we set TimerEnable.1, which then is checked in the Main loop, which then
; sets PORTC.1 Output high for the duration of the counter.
;*******************************************************************************
RelaySense: 
    TempIOCFlgs.byte0 = IOCAF  ; Copy IOC Flags to a temp register.
    TempIOCFlgs.byte1 = IOCBF  ; Copy IOC Flags to a temp register.
    for GPCounter = 0 to 15   
        if TempIOCFlgs.0[GPCounter] = 1 then  ; Check each flag to see if it's set.
            TimerEnable.0[GPCounter] = 1      ; If so, set Timer enable flags to check in Main loop.
'            TempPortS.0[GPCounter] = 1
        endif
    next GPCounter


    TempIOCAF = IOCAF ^ $FF    ; Clear the individual interrupt flags.
    IOCAF = TempIOCAF & IOCAF


   
    TempIOCBF = IOCBF ^ $FF    ; Clear the individual interrupt flags.
    IOCBF = TempIOCBF & IOCBF


@ INT_RETURN


;*******************************************************************************
; Timer 1 interrupt handler toggles StatLED1 as our heart beat.
;*******************************************************************************
ToggleLED1:
    toggle StatLED1    ; Toggle Heart Beat LED once per a little over 1 second.
@ INT_RETURN


;*******************************************************************************
; CODE STARTS HERE.
;*******************************************************************************
; Start of program.  We clear all variables, initialize those that need to be
; and turn on our Status LEDs for half a second.
;*******************************************************************************
Start:
    clear
    IOCAF = $FF            ; Clear PortA IOC flag register.
    IOCBF = $FF            ; Clear PortB IOC flag register.
    TempPortS = $FFFF      ; Initialize variable.
    LATE = 0                ; Turn on Yellow Stat LEDs.  LED check and Version header.
    pause 800              ; Wait 1/2 Second.
   
    StatLED2 = 0            ; Turn on Yellow Stat LED.    Display binary number 1.
    StatLED3 = 1            ; Turn off Yellow Stat LED.   
    StatLED4 = 1            ; Turn off Yellow Stat LED.
    pause 800              ; Wait 1/2 Second.
    LATE = 7                ; Turn off Yellow Stat LEDs.
   
    StatLed1 = 1            ; Toggling the Blue led indicates sub-version or decimal point.
    pause 300
    StatLed1 = 0
    pause 300
    StatLed1 = 1
    pause 300
 
    StatLED2 = 0            ; Turn on Yellow Stat LED.    Display binary number 3. 
    StatLED3 = 0            ; Turn on Yellow Stat LED.     
    StatLED4 = 1            ; Turn off Yellow Stat LED. 
    pause 800              ; Wait 1/2 Second.
    LATE = 7                ; Turn off Yellow Stat LEDs.


    T1CON.0 = 1            ; Enable Timer 1


@ INT_ENABLE  TMR1_INT      ; Enable Timer 1 interrupts   
@ INT_ENABLE  IOC_INT      ; Enable Interrupts On Change interrupts


;*******************************************************************************
;*******************************************************************************
; Main loop where we check the TimerEnable flag bits to see if they are set.
; If set, then we set the SurgeCntX output high, decrement the SCCounter until
; it reaches ZERO, and then clear the output and our TimerEnableX flag bit.
; Output pulse is 300mS long.
;*******************************************************************************
Main: ...

The code below shows what I do and when I start to use the heart beat.

Help with Using the Catalex MP3 Player

$
0
0
Hi Thank you for reading

I am using a Catlex MP3 Player (It was Cheap) from ebay to play specific sound bytes driven from a GPO dial telephone.... Dial 3 it plays track three, dial 7 it plays track 7 etc.

I would expect the code to go back to scanning the dial waiting for the next number dialed after the playing message has finished.

But:- Every so it just stalls and wont do anything till I reset.

Do I need to tidy up anything or have I missed anything obvious .... I am not a software guy at all so go easy on me.

Code:

' Name      : Messages.pbp
' Compiler    : PICBASIC PRO Compiler 2.6
' Assembler  : MPASM
' Target PIC  : PIC16F628A
' Hardware    : VeroBoard
' Oscillator  : 4 Megs External
' Keywords    : MP3 Messages
' Description : Messages
' Using the Catalex MP3 Player.
           
           
            DEFINE OSC 4        'Set oscillator in MHz
            'OSCCON = $60  '4 Megs Xtal
            TRISA=0        'Port A all outputs
            TRISB=%00001100 'Make RB3 and RB4 inputs
            'OPTION_REG.7=0 'Enable internal pull-ups
            CMCON=7        'No Analogs
           
           
            DEFINE HSER_TXSTA 24H  'Set transmit status and control
            DEFINE HSER_RCSTA 90H  'Set receive status and control
            DEFINE HSER_BAUD 9615  'Baud Rate 9600 Catalex Uart
            define HSER_CLROERR 1  ' Clear Buffer
            define HSER_SPBRG 25    '
           

' Alias pins
            HOOK Var PORTB.3    'Hook input
            PULSE VAr PORTB.4      'Pulse Input
            VOL con 20              ' Volume Level 0 to 30
            MESSAGE Var word        ' Message Number 
           
            hserout [$7E,$FF,$06,$09,$00,$00,$02,$EF] 'Select TF Device
            pause 200         
            hserout [$7E,$FF,$06,$06,$00,$00,$14,$EF] 'Volume Set
            pause 200
            Gosub shhh              'Stop playing
            'pause 20
           
           
dial:      count pulse,5000,Message
            pause 10
           
           
            if message=1 then  'Mess1
            gosub Track1
            ENDif
            if message=2 then  'Mess2 
            gosub Track2
            endif
            if message=3 then  'Mess3
            gosub Track3
            Endif           
            if message=4 then  '
            gosub Track4
            ENDif           
            if message=5 then  '
            gosub Track5
            ENDif
            if message=6 then  '
            gosub Track6
            ENDif
            if message=7 then  '
            gosub Track7
            ENDif
            if message=8 then  '
            gosub Track8
            ENDif
            if message=9 then  '
            gosub Track9
            ENDif
            if message=10 then  '
            gosub Track10
            ENDif
           
            goto dial
           
           
track1:    gosub shhh
            hserout [$7E,$FF,$06,$03,$00,$00,$01,$EF] 'Message 1
            return
           
track2:    gosub shhh
            hserout [$7E,$FF,$06,$03,$00,$00,$02,$EF] 'Message 2
            return         
                       
track3:    gosub shhh
            hserout [$7E,$FF,$06,$03,$00,$00,$03,$EF] 'Message 3
            return
                     
track4:    gosub shhh
            hserout [$7E,$FF,$06,$03,$00,$00,$04,$EF] 'Message 4
            return         
               
track5:    gosub shhh
            hserout [$7E,$FF,$06,$03,$00,$00,$05,$EF] 'Message 5
            return
           
track6:    gosub shhh
            hserout [$7E,$FF,$06,$03,$00,$00,$06,$EF] 'Message 6
            return
           
track7:    gosub shhh
            hserout [$7E,$FF,$06,$03,$00,$00,$07,$EF] 'Message 7
            return   
           
track8:    gosub shhh
            hserout [$7E,$FF,$06,$03,$00,$00,$08,$EF] 'Message 8
            return
           
track9:    gosub shhh
            hserout [$7E,$FF,$06,$03,$00,$00,$09,$EF] 'Message 9
            return         
           
track10:    gosub shhh
            hserout [$7E,$FF,$06,$03,$00,$00,$0A,$EF] 'Message 10
            return
           
d_tone:    gosub shhh
            hserout [$7E,$FF,$06,$03,$00,$00,$0C,$EF] 'Tone low res
            return           
           
           
Shhh :      hserout [$7E,$FF,$06,$16,$00,$00,$00,$EF] 'Stop Playing
            pause 200
            Return                   
           
                     
       
  End

usbin

$
0
0
Hello all

i buid usb HID keyboard with pic18f2450
it work perfect, except to usbin command.
i want to read the status of caps lock,num lock,scroll lock
when i use usbin, the program stuck in a usbin loop.

i try all
please help :-)

Eyal
Attached Files

Newbie Manchester Coding question

$
0
0
So, I have a temperature sensor that reports in Manchester code. I need to decode it. Looking through the various examples on here leaves me confused about how to tackle this. Most of the code examples do bit conditioning/math to decode with no reliance on timing, but they all appear to rely on the assumption they're also providing the encoding process.

eg. http://www.picbasic.co.uk/forum/showthread.php?t=198


There's one example that decodes a 'foreign' device but that notably relies on timing as a central part of the process.

eg. http://www.picbasic.co.uk/forum/showthread.php?t=10768

I was under the impression that to successfully decode my device, I also need to rely on timing as there are short and long pulses of data?

Thanks,

Troy

Watchdog timer not working as expected

$
0
0
Hello
I've got a problem on a PIC18F65J11 using PICBasic PRO 3.1 with the watchdog timer.

I am testing some software but after a few hours of running it hangs up. The watchdog timer is enabled and I would assume that a WDT reset restarts the system.
In order to test the proper function of the watchdog I wrote a little software that lights up LED1 on startup and then in the main loop flashes LED2. With the watchdog in the configuration bits enabled, the 'define NO_CLRWDT 1' and a 'clearWDT' instruction in the main loop the program runs fine. Then I remove the 'clearWDT' instruction in the software and run the program again. At startup LED1 ligths up and LED2 flashes for some time until the WDT runs into a timeout. Now I would have expected that a reset restarts the software and LED1 lights up and then LED2 flashes and so on. But there seems to be no restart. Somewhere the system hangs. To make sure that the reset vector is correct I added the 'RESET_ORG 0h' define at the start.

To check to proper hardware function of the WDT I've written the same software in C, compiled it with XC8 and it works as expected: after the WDT runs into the timeout a reset starts the program again.

Here is the software:

The configuration bytes are:
0000- f4a1 f904 f0f8

Code:

DEFINE OSC 8
define RESET_ORG 0h
define NO_CLRWDT    1

DEFINE DEBUG_REG PORTD
DEFINE DEBUG_BIT 5
DEFINE DEBUG_BAUD 2400
DEFINE DEBUG_MODE 1


  Clear 'Alle Variabeln löschen
  OSCCON=110000  'Set to 8 MHz

  Low PortD.6        ' LED2
  low PortD.7        ' LED1
  low PortB.2

  'Init Interrupts
  PIR1  =000000 'clear all Interrupt flags
  PIE1  =000000 'turn on USART Receive '+ P1_AD Interrupt  'V174
  INTCON=000000 'turn on Global Interrupts and Periph Interrupts
  INTCON2=000000 'PORT B Pullup disabled
  SSPCON1.5=0 'Disable SSP
 
PortD.7 = 1
Pause 1000
PortD.7 = 0

MainLoop :

    PortD.6 = 1
    Pause 100
    PortD.6 = 0
    pause 100

GoTo Mainloop

Rigth now I am at loss as to what could be wrong. Any help would be appreciated.

Regards
WaaxNOX

Complex math on 16F series?

$
0
0
Code:

d = 1 / ((x1 - x2) * (x1 - x3) * (x2 - x3));
a = d * (x1 * (y3 - y2) + x2 * (y1 - y3) + x3 * (y2 - y1));
b = d * (x1 * x1 * (y2 - y3) + x2 * x2 * (y3 - y1) + x3 * x3 * (y1 - y2));
c = d * (x1 * x2 * y3 * (x1 - x2) + x1 * x3 * y2 * (x3 - x1) + x2 * x3 * y1 * (x2 - x3));
y(x) = a*x*x + b*x + c

Code:


Code:


Hello, there is some math to be done to calculate polynomial smoothing points. Fragment of code is shown above. X and Y will be in range of 100-900.
If I understand correctly, there is no way to calculate that on 16F core and need to go for 18F core, right?

Doing something at predefined amount of steps?

$
0
0
Hello and sorry for bogus title, I just can't explain it simpler in short terms :)

The idea is as follows, there is a variable, incremented from 1 to say 1000.

There is something to be done in each 5, 19, 23, 49 or whatever step of that variable.

On ZX Spectrum, I was using thing like: IF I/21=INT(I/21) THEN xxxx

Here we don't have floating math, so trick with INT won't work. So I came up with the following solution - inside the main variable loop, there's another helper variable, which is incremented by 1, along with main variable. When it reaches predefined value - say 84, we do the thing we have to do, and also reset that variable, so count starts again.

Are there other ways of doing that more simple?

Interfacing a BME280 on a PIC18F2431

$
0
0
Hello Everyone,

I'm currently interfacing a BME280 digital humidity, pressure and temperature sensor (I²C) with a 18F2431:
https://www.bosch-sensortec.com/bst/...roducts/bme280

I have it up and communicating, however I've come to the temperature/pressure/humidity calculations. They seem quite complex and I was hoping that someone has some experience using them with PBP?

Do you know if the calculations are even possible with PBP?
Does anyone have some sample code I could have a look at?

Thanks,

Annoying MicroCode Studio quirk/issue

$
0
0
I'm using Microcode Studio ver 5.0.0.5 and I'm a bit miffed at a very minor, yet annoying issue.

I have a bunch of program tabs open at the top; 2 of which let's call "Program A" and "Program B".
"Program A" is configured to use a 12F1840 whilst "Program B" is configured to use a 16F1788.
If I'm currently accessing/editing Program B and click on the Program A tab, the microcontroller dropdown selector gets updated with Program A's 12F1840 (all good). But if I do exactly the same thing the other way: click on Program B from accessing/editing Program A, the microcontroller dropdown doesn't get updated and I need to manually select the 16F1788 every time.
Any idea what causes this or methods to stop it from happening?

Thanks,

Troy

the simplest way to remotely control a pic?

$
0
0
i would control the pwm port from a distance of about 4-6 meters, i don't have experience with aerial (wifi, am modulation etc) so i would try to avoid them for a more simple thing (wired?)
Viewing all 4743 articles
Browse latest View live