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

How to send number greater than 65535 to MAX7219 BCD decoder?

$
0
0
I'm using 16F chip, so no support for long variables. But I have 8 digit led display connected to MAX7219 and I want to display on it say something like this

variable 1 (2 digits) "-" sign, variable 2 (2 digits) and again "-" sign, variable 3 (again 2 digits). The code I'm using is this, but it can't display more than 65535 due to compiler limitations. Any ways to solve this?

Code:

'DEFINES:
 Clk    Var PORTC.6  ' Data is clocked on rising edge of this pin            mcvane
 Dta  Var PORTC.5  ' Bits are shifted out of this pin          KVITELI
 Load    Var PORTC.4  ' Transfers data to LEDs when Pulsed  lurji
 
 
 'MAX7219 STUFF
    ' ** Declare Constants **
 Decode_Reg  Con 9 ' Decode register, a 1 turns on BCD decoding for each digit.
 Lum_Reg  Con 10 ' Intensity register.
 Scan_Reg Con 11 ' Scan-limit register.
 Switch_Reg Con 12 ' On/Off Register.
 Test_Reg Con 15 ' Test mode register (all digits on, 100% bright)
 Max_Digit Con 4 ' Amount of LED Displays being used.
' ** Declare Variables **
  Counter  Var Word ' Variable used for the Demo Counting routine
 Max_Disp Var Word ' 16-bit value to be displayed by the MAX7219
 Max_Dp  Var Byte ' Digit number to place Decimal point (0-4)
 Register Var Byte ' Pointer to the Internal Registers of the MAX7219
 R_Val  Var Byte ' Data placed in Each Register
 Digit  Var Byte ' Position of individual numbers within MAX_Disp (0-3)
 Position Var Byte ' Position of each LED display (1-4)
 
 ' Turn Off test mode
 Register=Scan_Reg  ' Point to the Scan Register
 R_Val=6    ' send 3, (Four LED Displays 0-3)
 Gosub Transfer  ' Transfer this 16-bit Word to the MAX7219
 Register=Lum_Reg  ' Point to the Luminance Register
 R_Val=1    ' Send 5, (Value for Brightness)
 Gosub Transfer  ' Transfer this 16-bit Word to the MAX7219
 Register=Decode_Reg  ' Point to BCD Decode Register
 R_Val=%11111111  ' Decode the first 8 digits
 Gosub Transfer  ' Transfer this 16-bit Word to the MAX7219
 Register=Switch_Reg  ' Point to the Switch Register
 R_Val=1    ' Set to One, (switches the display ON)
 Gosub Transfer  ' Transfer this 16-bit Word to the MAX7219
 Register=Test_Reg  ' Point to the Test Register
 R_Val=0    ' Reset to Zero, (turns off Test mode)
 Gosub Transfer  ' Transfer this 16-bit Word to the MAX7219

TTK:

for tvla=50000 to 65535
pause 10
max_disp=tvla
GOSUB DISPLAY
next
GOTO TTK
 
Display:
 Digit=0      ' Start at Digit 0 of Max_Disp Variable
 For Position=1 to 5 'step -1  ' Start at Farthest Right of Display 
 Register=Position    ' Place Position into Register
 R_Val=Max_Disp Dig Digit  ' Extract the individual numbers from Max_Disp 
 If Max_Disp<10 and Position=3 then R_Val=15 ' Zero Suppression for the second digit
 If Max_Disp<100 and Position=2 then R_Val=15 ' Zero Suppression for the Third digit
 If Max_Disp<1000 and Position=1 then R_Val=15 ' Zero Suppression for the Forth digit
 If Max_Disp<10000 and Position=0 then R_Val=15 ' Zero Suppression for the Fifth digit
 If Digit=Max_Dp then R_Val.7=1  ' Place the decimal point, held in Max_DP
 Gosub Transfer    ' Transfer the 16-bit Word to the MAX7219
 If Digit>=4 then Digit=0  ' We only need the first five digits
 Digit=Digit+1    ' Point to next Digit within Max_Disp
 Next Position    ' Close the Loop
 Return      ' Exit from subroutine
' Send a 16-bit word to the MAX7219
Transfer:
  Shiftout Dta,Clk,msbfirst,[Register,R_Val] ' Shift Out the Register first, then the data
 High Load    ' The data is now acted upon
 PAUSEUS 100
@ Nop
@ Nop    ' A small delay to ensure correct clocking times
 Low Load    ' Disable the MAX7219
 Return    ' Exit from Subroutine


Modifying melabs sample code to set time to 24 hour for DS1302 ?

$
0
0
Hello.
I'm dealing with this:

http://melabs.com/samples/LABX1-16F877A/rtcx.htm

It works fine, but I want it to display time in 24 hour format, not in AM/PM.
After reading DS1302 datasheet, I've found out that I need to set bit 7 to 1 and write this to register 84H. However, the code above bursts only 8 bytes, how can I modify it to write to appropriate register?

Christmas Activity

$
0
0
Jingle bells, jingle bells... Christmas is coming soon. In order to celebrate Christmas, ALLPCB now hold an activity " Finding PCB Christmas Tree " from 2018.12.17 to 2018. 12. 25 in Facebook.


Activity Rules :


1. Log in Facebook and search @ALLPCBOfficial


2. Post your PCB Christmas tree or the PCB Christmas tree you have seen to the comment area. The tree is made with PCBs and each person can only comment for once.


3. The top 5 comments which win most quantity of " like " will get coupon. ( " like " should more than 10 or invalid )


Awards:
Top 1 can receive $60 coupon


Top 2 can receive $50 coupon


Top 3 can receive $40 coupon


Top 4 can receive $30 coupon


Top 5 can receive $20 coupon


( by the way, register ALLPCB now and you will get $10 coupon as well. )






Activity Time: From 2018.12.17 to 2018. 12.24, the result will be announced at 2018.12.25.


The PCB Christmas tree can bring you fun and win ALLPCB coupon, why not join us?


ALLPCB aims at providing high-quality and cost-effectively PCBs for all engineers, you can search our eariler news for more offers.


1. PCB substrate free upgraded (Tg 140, Tg 150, Tg 170 are avaliable ).


2. 20% off for PCB orders.


3. only $50 for 5pcs SMT PCBA.

Neopixel shocker ?

$
0
0
Thought I'd pursue toying around with a 16 led Neopixel ring I bought, so have been searching a bit for code examples using Picbasic pro and it seems there is more to this than meets the eye. --- really ? (!) The code I saw included some lengthy "include" code and a lot more than I imagined.

Is it that complex? Doesn't each LED just basically need 3 bytes of color information and a bit to turn it on ? Any samples and basics anyone can point me to? A lot of Arduino stuff out there but who cares.

xc8 time.h dst

$
0
0
has anyone tried daylight savings time in xc8 ? // google yields no clues that I can find

basic time structure is
from time.h
Code:

struct tm {
 int tm_sec;
 int tm_min;
 int tm_hour;
 int tm_mday;
 int tm_mon;
 int tm_year;
 int tm_wday;
 int tm_yday;
 int tm_isdst;

whether dst is 0 or 1 or -1

makes no difference to the

localtime() - gmtime() = time_zone


I was expecting a 60 min difference with dst on

SPIMAST + SPISLAVE adapted to 16F690

$
0
0
Hi there,

Wanting to learn about SPI communication using the PIC's hardware feature, I've slightly adapted both SPIMAST and SPISLAVE examples to make them fit into a PIC 16F690.

But I've been struggling for hours trying to make them work with no too much luck.

Unfortunately, I don't have a data/logic analyzer so I trust my oscillo to show me some "activity" on the SDO ports.

With the adapted code(s) here under, SPIMAST_16F690 is sending something. Unfortunately, SPISLAVE_16F690 doesn't "answer" (no signal on SDO).

Since I haven't any 40 pin PIC around, I can't test the example program(s) as is (...are) so I might miss something.

But what?
Attached Files

Merry Christmas And a Happy New Year...

$
0
0
From Me, I hope you all have a merry Christmas and a happy new year.

N8NTA,

IOC on 16F1939

$
0
0
Trying to make use of DT-INTS-14 on a 16F1939 and detect Change on Port B.

Code:

'-------------  INTERRUPTS SETUP  ---------------------
ASM
INT_LIST  macro;    IntSource,  Label,      Type,  ResetFlag?
    INT_Handler    RBC_INT,    _keybrd,    PBP,    yes
    endm
    INT_CREATE            ; Creates the interrupt processor
ENDASM

@  INT_ENABLE  RBC_INT      ; Enable Port B on change

The above code gives an error:
... : ERROR: ("INT_ENABLE" - Interrupt Flag ( INTCON,RBIF ) not found.)
... : ERROR: ("INT_Handler" - Interrupt Flag ( INTCON,RBIF ) not found.)

So, that means the DT-INTS14 does not support the IOC of 1939?

Ioannis

Two questions / errors

$
0
0
Hi All!
It has been a while since I was doing anything with PICs and now I am trying again! Okay, so one question is I could have sworn when you wrote a program you would see line numbers? I cannot figure out how to turn on this option or has it been eliminated? Second question is I get an error message that reads "You have chosen to compile your program with ICD capabilities. The PICmicro will not run unless activated with the ICD toolbar". This is the new 3.1 version I am trying to set up.


Thanks.

HSERIN/HSEROUT strange behavior receiving data with DEC modifier

$
0
0
Hi All,

I'm facing a problem I don't know the answer.

I'm running this code with a serial comm loopback (MCS's Serial Communicator).

As long as I'm sending 100% correct data (3 digits between 0..255) from the terminal, everything is okay.

If I send, lets say, the number 270, then it goes weird. The terminal receiver will continue to receive data (I can see the incoming byte counter) but the display won't update anymore. Even if I correct the sent data, it will not work until a re-flash the chip (?!).

Any idea what is wrong? Is it something with the DEC modifier? :confused:

Code:

' PIC 16F690, 4MHz crystal

@ __config _FCMEN_OFF &_IESO_OFF &_CPD_OFF &_WDT_OFF &_HS_OSC &_BOR_OFF &_CP_OFF &_PWRTE_OFF &_MCLRE_OFF

@ ERRORLEVEL -306  ; turn off crossing page boundary message
 
' ====== REGISTERS =================================================================================
' Registers  76543210
OPTION_REG = %10000000 ' PORT A&B Pull-Ups and Prescaler
OSCCON    = %00000000 ' External
ANSEL      = %00000000 ' Analog inputs Channels 0 to 7
ANSELH    = %00000000 ' Analog inputs Channels 8 to 11 <3:0>
ADCON0    = %00000000 ' A/D Module
CM1CON0    = %00000000 ' Comparator1 Module
CM2CON0    = %00000000 ' Comparator2 Module
INTCON    = %00000000 ' INTerrupts CONtrol
TRISA      = %00000000 ' Set Input/Output (0 to 5)
PORTA      = %00000000 ' Ports High/Low  (0 to 5)
TRISB      = %00000000 ' Set Input/Output (4 to 7)
PORTB      = %00000000 ' Ports High/Low  (4 to 7)
TRISC      = %00000000 ' Set Input/Output (0 to 7)
PORTC      = %00000000 ' Ports High/Low  (0 to 7)

' USART registers (RX=PORTB.5, TX=PORTB.7) - for serial DEBUG
RCSTA      = $90      ' Enable serial port & continuous receive
TXSTA      = $20      ' Enable transmit, BRGH = 0
SPBRG      = 12        ' 4800 Baud @ 4MHz, 0.17%

TRISB.5    = 1        ' make PORTB.5 an Input
TRISB.7    = 0        ' make PORTB.7 an Output
PORTB.5    = 1        ' set to avoid sending serial data garbage

' ====== DEFINES ===================================================================================
DEFINE OSC 4
DEFINE NO_CLRWDT 1  ' Don't waste cycles clearing WDT 
DEFINE HSER_CLOERR 1 ' Automatic clear overrun error

' ====== VARIABLES =================================================================================
MyData  VAR BYTE

' ====== INITIALIZE ================================================================================
MyData = 0

' ====== PROGRAM TOP ===============================================================================
MAIN:

    ' Send serial data
    HSEROUT ["OUT ",DEC3 MyData,13]

    ' Receive serial data
    HSERIN 500, MAIN,[WAIT("IN"),DEC3 MyData]
       
    GOTO MAIN

END

Loop algo problem

$
0
0
I am trying to make a complex loop and I suppose I am in a wrong mind loop...

The project need a time base. Done in a ISR that counts seconds and minutes OK.

The request is to have a var value change according to data read from an EEPROM. That data include the time and setpoint.

Example:

Phase 1: For 1 minute
change value from setpoint1 to setpoint2 and reverse every 20 seconds

Phase 2: For 2 minutes
change value from setpoint1 to setpoint2 and reverse every 30 seconds

My ISR is this:
Code:

timer:                    'Timer 1 tick every 1us x 50000 = 50ms
    t1con.0=0            'time variable inc every 50ms
    if time<19 then      'x 20 = 1sec
        time=time+1
    else
        time=0
        if seconds>0 then 'dec seconds
            seconds=seconds-1
        else
            seconds=59
            if minutes>0 then  'dec minutes
                minutes=minutes-1
            else
                minutes=59 'reload minutes from settings
            endif
        endif
        IF p_seconds>0 then p_seconds=p_seconds-1
    endif
    tmr1l=$b7  'reload timer 1  with 16474
    tmr1h=$3c  '65536-49062
t1con.0=1  'start timer 1

@ INT_RETURN

The data are read from the EEPROM using a For-Next loop in 4 byte group:

Code:

for addr2=start_addr to end_addr step 4
    i2cread data_pin, clk_pin, contr, addr2, [Minutes, setpoint1, setpoint2, change_seconds_period]

Then there is this wrong loop that does not work correctly. It goes to the next phase when change_seconds_period expires.

Code:


temp_change_seconds_period=change_seconds_period
value=setpoint1

loop1:
        while minutes>0
            if change_seconds_period=0 then loop2
            if temp_change_seconds_period=0 then 'change over setpoints
                value=setpoint2
                temp_change_seconds_period=change_seconds_period 'reload change period
            endif
  loop2:
            if !but_stop then stop_prg  'test for user interaction
            if !but_pause then pause_prg  'test for user interaction
        lcdout $fe,line3,"Phase ",#phase,$fe,line4,dec3 value," ",dec3 minutes," ",dec3 temp_change_seconds_period
        wend
       
phase=phase+1   
next addr2

Any help appreciated.
Ioannis

APA102 clear leds ?

$
0
0
By chance if anyone knows, I'm using a 12F675 and PBP to run a string of these leds and all is fine except I want to do a loop where they clear and sequence again.

I know there is a start frame, the actual led frame(s) and an end frame which from what I gather is either is multiple bytes of all 1 or all 0. (I'm using 255, all 1's) Anyway, I want to run a sequence over and over but can't figure out how to extinguish all the leds.

Is the start frame supposed to do it? (guess not -- because it isn't). I'm using an SK9822 string which is supposedly a clone of APA102 btw.

Thanks much.

How do I send MANCHESTER encoded data over serial comm?

$
0
0
Hi All,

I am wondering how I can really send MANCHESTER encoded data over serial comm.

I'm tuning up a project involving the use of RF modules (such as TLM434) where MANCHESTER coding makes it possible to use them. Actually it works, but not with 100% reliability; in fact, it's much, very much less.

For any reason, I didn't notice up to now that my MANCHESTER encoded sent data doesn't really look like to be MANCHESTER encoded.

Attachment 8834

Where in the green square I send "U" characters as a preamble (%01010101), the "MANCHESTER encoded" data (see a piece of it in the orange square) shouldn't, IMHO, look like this.

This is the way I send the data:
Code:

...
HSEROUT ["UUU!",Encoded,13]
...

...where Encoded is a WORD variable (containing i.e.: 182 => 10110110 => 1001101001101001).

MANCHESTER coding should format the data to be at a maximum of two similar logic signals in a row (or I got it wrong).

Where a "0" or a "1" lasts (in this example @ 4800bps) 0.2ms as seen in the green square, a "00" or "11" MANCHESTER encoded sequence should not be greater than 0.4ms. But, as you can see in the orange square, this low state lasts 0.8ms meaning I send four zeros in a row (!?).

So, how do I do this?
Attached Images
 

Filling an array

$
0
0
Happy New Year to All-
I am trying to do a simple dumb thing and the complier barks at me. I am trying to fill an array with hex numbers.
Example below:
x var byte 'Loop counter var
L0B0 var byte[16] ' Loop Zero, Board Zero port array
For x=1 to 16
Lookup x,[$80,$80,$80,$80,$81,$80,$80,$81,$80,$80,$80,$81,$8 0,$80,$80,$81],L0B0[x]
next x

Error I get is:
Output parameter must be a variable

I am certain I have stared at it so long that I don't see the obvious so I am reaching out.
Regards to All!

ATTINY85 programming

$
0
0
I bought this Tiny AVR programmer --

https://www.sparkfun.com/products/11801

I've never had any experience with it. It needs the Arduino IDE which I installed but can anyone tell me will there be a way I can program a TINY85 chip with my Picbasic hex file ? Or will it be a pain in the ___ ? Thanks much.

Instant Interrupts and a 18F8680

$
0
0
I am trying to use the RX1_INT in DT's Instant Interrupts with this chip and I get an error (actually 3 of them):
NODE1.ASM (785) : Symbol not previously defined (RC1IF)
" " (1365) "
" " (1390) "

I have used these great tools before without ever looking under the 'hood'.
Any guidance would be helpful.
Regards.

PIC to Pic Signaling

$
0
0
I have seen enough information on serial transfers to be sure there are people doing this, I'm just not sure the best way to inform the main controller that a secondary module has data and is waiting to deliver (serial) it.
.
What I have is a 12F683 based module that decodes I/R and formats 12 byte commands (1 byte device, up to 10 byte parameters and finally a delimiter) for an 18F4420 based aquarium controller. My questions revolve around interfacing the two…
.
I know that I can run a line between the two and have the master signal “READY” (HIGH or LOW) to initiate a transfer if there is a command waiting. I think that using a pull down on the line would provide a more robust means to listen and respond in duplex. I’m left wondering, is there a better or standard way of doing this? Is it traditional to use a second line... sort of a RTS line? Is it typical to share a clock signal? Those types of considerations.
.
I’m not looking specifically for code (not saying no); rather, strategies or best practices or even search hints – I can’t find anything on this.

PWM Motor Control with Soft Start, Soft Stop Example Please

$
0
0
Hi All,

It has been a while!

I need to drive a small 12v motor with PWM speed control to include soft start and stop. I would like to keep the circuit board small and I have a bunch of 675's at my disposal. Ultimately I would like to use a single pot to determine both speed and direction with half-way being the motor stop position. Can you point me to some fairly simple code examples (it has really been a while :-) to get me going?

Thank you!!!

Ross

SD or MMC card as storage for logging

$
0
0
  • Thanks, I'll download this and see what I can learn. I appreciate your help.

    Mike




Dave Houston

$
0
0
One of our active members, Dave Houston has not been present since 2016. Also his site is down.

Anyone knows why?

Ioannis
Viewing all 4794 articles
Browse latest View live


Latest Images