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

LCD frustration when I use MPASM assembler.

$
0
0
Hello dear friends,

I am a newcomer in PIC world. I've started to learn PBP by using of the “PM” assembler and I’ve found it very easygoing and fluent. And I have never ever faced with any serious problem on what ever I have done with this well-known assembler.

For achieving to instant interrupts I decide to use the valuable codes and methods of Mr. Darrel Taylor. And as you know it needs to get involved with MPASM.

With MPASM I can handle inputs and outputs as well, but the first serious problem is with the “LCDOUT” command. For example this below code shows text on all HD44780 LCDs by using of the “PM” assembler, but if I compile the same code with MPASM, the LCD will absolutely frustrate to show even an unknown character. There is nothing really.

Would you please let me know, where is the Achilles heel?

LCD:4*20 (same story with other HD44780 lcds such as "1*16" & "2*16" etc)

Code:

define osc 20define lcd_dreg portb
define lcd_dbit 4
define lcd_rsreg portb
define lcd_rsbit 1      '* Reset Bit port B.1
define lcd_ereg portb
define lcd_ebit 0        '* Enable Bit port B.0
define lcd_bits 4
define lcd_lines 4
main:
lcdout $FE,1
lcdout $FE,$C0,"**Second line**"
lcdout $FE,$94,"******Third 3 Line"
lcdout $FE,$D4,"******  4 th LINE"
lcdout $fe,2,"Goto First 1st LINE"

Herewith there are some screen shots of what I have used:
Attachment 7831Attachment 7832Attachment 7833Attachment 7834

All suggestions are welcome and I am just waiting...

Best regards,

Andy

P.S. Windows 7 - 32bits as O.S. and I've already added PBP and MPASM to the "PATH" of O.S. (windows path I mean)
Attached Images
    

this the nam for comandar site ffdbf

4 x AM2302's and 4 x 18B20's

$
0
0
Guys, just wanted to do a big shout out for TabSoft for producing a new include file for the AM2302 (and similar) range of humidity / temp sensors.

I'm in the process of upgrading the functionality of my reptile habitat controller that I produced back in 2010 with the assistance form DT and Henrik, and with TabSoft's new library file adding the additional AM2302's has been a breeze... Here's proof of the pudding so to speak...

2 x DS18B20's connected and 4 x AM2302's

Anyone using these range of sensors (aka DHT 22, DHT11, AM2302) then download the library file in the code example section
Attached Images
 

LCD showing mostly jibberish on 16F716

$
0
0
I've had a break from PIC's for a little so I'm a bit rusty, but I don't recall having this many issues in the past.

Just trying to get an LCD to work first on my 16F716. I haven't used this pic before so might have some config wrong.

B4-B7 goto DB4-DB7 on my 2-line LCD
RW is held low VIA code, Enable and RS are on corresponding pins.

The issue is that I get mostly jibberish all over the screen changing constantly, with glimpses of the text I'm trying to put there. I've mostly used 4-line LCD's before so don't even know if I have the addressing right, I dont' have a datasheet for this exact LCD
I have tried fiddling the COMMANDUS and DATAUS values but they haven't had an effect, even without them there.


Code:

@ __CONFIG    _WDT_ON & _RC_OSC & _PWRTE_ON

' Define LCD registers and bits
DEFINE  LCD_DREG        PORTB
DEFINE  LCD_DBIT        4
DEFINE  LCD_RSREG      PORTB
DEFINE  LCD_RSBIT      3
DEFINE  LCD_EREG        PORTB
DEFINE  LCD_EBIT        1
DEFINE  LCD_LINES      2

DEFINE LCD_COMMANDUS 1500        'defines the delay after LCDOUT statement
DEFINE LCD_DATAUS 44                'delay in micro seconds

TRISA = %11111
TRISB = %00000000

butdn          var porta.4
butup          var porta.3
butmode        var porta.2
bail2          var porta.0
bail3          var porta.1

clutch          var portb.0
lcdrw          var portb.2

c              var word
c = 0
lcdrw = 0

pause 150
lcdout $fe,1
pause 500
Start: '************************************************************************  START
c = c + 1
lcdout $fe,1
lcdout $fe,$00,"This is a test "
lcdout $fe,$40,DEC c
pause 500
if c > 100 then
  c = 0
endif
GOTO start

PIC16F676 troubles

$
0
0
I've chosen the 16F676 for size and cost and it also has an ADC which I also need. I need to use all the I/Os and I need to use PORTA.3 (MCLR) as a digital input to be used with a button. The "big" program isn't working so I've broken it down into smaller parts to make sure everything is working correctly. Below is the code to use the button to toggle an LED on and off. The start up works and the button turns the LED on, but only one time. Once the LED is toggled on for the first time, it gets stuck. What am I doing wrong?

Code:


#config
    __CONFIG _CP_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT & _MCLRE_OFF
#endconfig


TRISA = 001000


LED var PORTA.1
PUSHBUTTON var PORTA.3


'***********************start up just to make sure LED is working**************************
led = 1
pause 100
led = 0
pause 100
led = 1
pause 100
led = 0
'***************************************************************************************
main:


    if PUSHBUTTON = 0 then
       
        toggle led
        pause 25
       
    endif
   
goto main
end

Need to flip order of bits MSB to LSB re: MCP23S17

$
0
0
Hello all!

I am using a couple of MCP23S17's with a PIC18F2320 in order to communicate with a circuit that converts a 24 bit parallel output from the MCP23S17's to a fiber optic signal.

The fiber signal requires timing that the PIC just cannot do, unfortunately, so a bunch of standard logic does the fast stuff, and the PIC handles feeding values in parallel via the port expanders (MCP23S17's)

I'm using some code that I borrowed from here: http://www.picbasic.co.uk/forum/cont...P-PBP-MSSP-ASM

The first variation to be exact. I've modified it to work with my circuit, as it includes two MCP23S17's, one of them only using 8 bits and the other using all 16 bits

The MCP23S17 that handles 8 bit's of the full 24 bit packet is easy to deal with because the data is pretty much static and each of the 8 bits is handled as an individual, so no problem there.

The problem is that the other 16 bits need to be handled as a singular WORD for a 16 bit numerical value. It's nice and easy doing math on an integer, etc.

The way the code example works is that it sends everything to the MCP23S17 MSB first. My value has to be transmitted LSB first!

So to the code %1000000000000000 looks like "32768" but if I send that, my circuit thinks it's "1"!!!

So how do I go about reversing the bit order just before I send it on its way to the MCP23S17?

I already have the PCB made, so I can't simply change my bit order by wiring or I would just do that. Trust me, I already have a "blue wire" or two "fixing" a bug or two, one you'll notice with PORTA.4, so I just shared a line with the other chip select, since the MCP's are hardware addressed anyway.

The following is test code, far from complete and fraught with other issues to work through.

Code:

' --------------------CHIP FUSES-------------------------------

@ __CONFIG    _CONFIG1H, _HS_OSC_1H & _FSCM_OFF_1H & _IESO_OFF_1H
@ __CONFIG    _CONFIG2L, _PWRT_OFF_2L & _BOR_OFF_2L
@ __CONFIG    _CONFIG2H, _WDT_OFF_2H & _WDTPS_1_2H
@ __CONFIG    _CONFIG4L, _STVR_OFF_4L & _LVP_OFF_4L & _DEBUG_OFF_4L
@ __CONFIG    _CONFIG3H, _CCP2MX_OFF_3H & _PBAD_DIG_3H & _MCLRE_ON_3H

DEFINE OSC 40
INTCON = 0
ADCON1.0 = 1                                    ' Turn off analog inputs
ADCON1.1 = 1
ADCON1.2 = 1
ADCON1.3 = 1
ADCON0.0 = 0                                                  ' Turn off analog converter
CMCON.0 = 1
CMCON.1 = 1
CMCON.2 = 1








' --------------------Ports---------------------------------------
          '76543210          '76543210
 TRISA  = %00000000: PORTA = %00000000
 TRISB  = %00000011: PORTB = %00000000
 TRISC  = %00000000: PORTC = %00000000

'                        ALIAS & MODIFIERS
' ================================================================
  nCSA VAR PORTA.3                                                       
  nCSB var PORTA.4 '- BAD - OPEN COLLECTOR! DO NOT USE
  nRST VAR PORTA.2
  SCLK VAR PORTA.1
  SDO VAR PORTA.0
  xmit Var PORTA.5
  UPbtn VAR PORTB.0
  DWNbtn VAR PORTB.1

'                        VARIABLES & COSTANTS
' ================================================================
 MCP23A CON $42    'Register address to MCP23S17 Config
 MCP23B CON $40    'Register address to MCP23S17 PortA(1)
 IOCON  CON $0A    'Register address to MCP23S17 Config
 IODIRA CON $00    'Register address to MCP23S17 PortA(1)
 IODIRB CON $01    'Register address to MCP23S17 PortB(2)
 GPIOA  CON $12    'Register address to MCP23S17 GPIOA(1)
 GPIOB  CON $13    'Register address to MCP23S17 GPIOB(2)
 OLATA  CON $14    'Register address to MCP23S17 LATA(1)
 OLATB  CON $15    'Register address to MCP23S17 LATB(2)
 
 
 DataOut var BYTE
 Voltage VAR WORD  'Variable for manipulating Voltage as full 16 bit word
 VoltageFst VAR Voltage.BYTE0 'Variable for Voltage Byte 0 to Send to MCP23S17A-A
 VoltageSec VAR Voltage.BYTE1 'Variable for Voltage Byte 1 to Send to MCP23S17A-B
 Param Var BYTE    'Variable for Parameters Byte to Send to MCP23S17B-A
 RD VAR Param.0    'Varible to set read bit on IP Board - 0 = Read
 WR VAR Param.1    'Varible to set write bit on IP Board - 1 = Write
 O4 VAR Param.2    'Varible unused 4
 RY VAR Param.3    'Varible to set Relay bit on IP Board - 1 = Relay Pulled
 O3 VAR Param.4    'Varible unused 3
 O2 VAR Param.5    'Varible unused 2
 CH1 VAR Param.6    'Varible bit 0 of ADC channel select
 CH0 VAR Param.7    'Varible bit 1 of ADC channel select
 AuxPort Var BYTE  'Variable for Aux Port Byte to Send to the MCP23S17B-B
 UPbtnvar Var BYTE  'Variable for UP Button
 DWNbtnvar VAR BYTE 'Variable for DOWN Button
 MCPReg  VAR BYTE  'Variable for the Register to Send to the MCP23S17
 MCPWRT var BYTE  'Command o write in MCP23S17 Address $00
 MCPRED var BYTE  'Command o read from MCP23S17 Address $00
'                            INIT 
' ================================================================
    UPbtnvar = 0
    DWNbtnvar = 0
   
    ncsa = 1
    'ncsb = 1
    nRST = 0                'Reset the port expanders
    PAUSE 1
    nRST = 1
   
    MCPReg = IOCON          'Configures MCP23S17-A
    DataOut = $28
    nCSA = 0                'Enable MCP23S17-A
    SHIFTOUT SDO, SCLK, 1, [MCP23A,MCPReg,DataOut]       
    nCSA = 1                'Disable MCP23S17-A
   
    MCPReg = IODIRA        'Configures PortA(1) All Output
    DataOut = $00
    nCSA = 0                'Enable MCP23S17-A
    SHIFTOUT SDO, SCLK, 1, [MCP23A,MCPReg,DataOut]       
    nCSA = 1                'Disable MCP23S17-A
   
    MCPReg = IODIRB        'Configures PortB(2) All Output
    DataOut = $00
    nCSA = 0                'Enable MCP23S17-A
    SHIFTOUT SDO, SCLK, 1, [MCP23A,MCPReg,DataOut]       
    nCSA = 1                'Disable MCP23S17-A
   
    MCPReg = IOCON          'Configures the MCP23S17
    DataOut = $28
    nCSA = 0                'Enable MCP23S17-B
    SHIFTOUT SDO, SCLK, 1, [MCP23B,MCPReg,DataOut]       
    nCSA = 1                'Disable the MCP23S17
   
    MCPReg = IODIRA        'Configures PortA(1) All Output
    DataOut = $00
    nCSA = 0                'Enable MCP23S17-B
    SHIFTOUT SDO, SCLK, 1, [MCP23B,MCPReg,DataOut]       
    nCSA = 1                'Disable the MCP23S17
   
    MCPReg = IODIRB        'Configures PortB(2) All Output
    DataOut = $00
    nCSA = 0                'Enable MCP23S17-B
    SHIFTOUT SDO, SCLK, 1, [MCP23B,MCPReg,DataOut]       
    nCSA = 1                'Disable the MCP23S17     

    AuxPort = %00000000
    GOSUB SEND_AuxPort             

                      '              _
                      ' |CH|--|RY|-|W|R
    Param = %00001010 '  00 00  1 0 1 0
    GOSUB SEND_Param
   
    Voltage = 0
    GOSUB SEND_Voltage
'                            MAIN LOOP
' ===============================================================

MAIN:

BUTTON DWNbtn,1,255,255,DWNbtnvar,1,BtnDwn

BUTTON UPbtn,1,255,255,UPbtnvar,1,BtnUp

GOSUB Transmit
   
GOTO MAIN

'                              SUB - ROTINES
' ================================================================   
BtnUp:
   
    IF Voltage >= 65535 THEN
    gOTO MAIN
    ENDIF
    Voltage = (Voltage + 1)
    GOSUB SEND_Voltage
  'pause 50
GOTO MAIN

BtnDwn:

    IF Voltage = 0 THEN
    GOTO MAIN
    ENDIF
    Voltage = (Voltage - 1)
    GOSUB SEND_Voltage
  'pause 50
GOTO MAIN

Transmit:
    xmit = 1
    PAUSEUS 1
    xmit = 0
pause 50
RETURN

SEND_Voltage:

    Voltage = Voltage REV 16

    nCSA = 0                'Enable MCP23S17-A
    SHIFTOUT SDO, SCLK, 1, [MCP23A,OLATA,VoltageFst]       
    nCSA = 1                'Disable the MCP23S17
    pause 1
    nCSA = 0                'Enable MCP23S17-A
    SHIFTOUT SDO, SCLK, 1, [MCP23A,OLATB,VoltageSec]       
    nCSA = 1                'Disable the MCP23S17
RETURN

SEND_Param:
    nCSA = 0                'Enable MCP23S17-B
    SHIFTOUT SDO, SCLK, 1, [MCP23B,OLATA,Param]       
    nCSA = 1                'Disable the MCP23S17
RETURN

SEND_AuxPort:
    nCSA = 0                'Enable MCP23S17-B
    SHIFTOUT SDO, SCLK, 1, [MCP23B,OLATB,Auxport]       
    nCSA = 1                'Disable the MCP23S17
RETURN

goto main

END

Sending text to GLCD using BV4511 interface

$
0
0
Hi,

I picked up a 128 x 64 GLCD with a ByVac BV6511 adapter board that uses the I2C interface (web site http://www.byvac.com/index.php/BV4611)

I'm totally confused....

Reading the datasheet for the device it seems to suggest that you use the i2c much in the same way as you would a serial instruction. I was hoping it would be as simple as using the normal LCDOUT type instruction, along the lines of I2CWRITE, data pin, clock pin, address, control, ["hello world"]

Looking at the datasheet even the address is confusing, page 4 gives it 0x32 (7 bit), 0x68 (8 bit). Page 5 states the default is 8 bit address of 0x68, but the 7 bit address is 0x34 ? I've tried using, substituting the $68 for $32 and $34 - no joy :(

Code:

I2cwrite SDA,SCL,$68,$0,[$27,"hello"]
Can anyone who is good at deciphering data sheets have a look at it and let me know if this will work in PBP

quick changing of ports for I/O use

$
0
0
Hi guys , was wondering where i should look in the electrical specs for the chip where the ports settle time between changing port inputs to output and back

have need to do fast transition of direction over a group of port pins over several ports

cheers

Sheldon

LED Blinking while main does something else

$
0
0
Hello, I am new to PIC programming and the forum so please be gentle. I was hoping someone could offer some suggestions on a program. I am using a PIC16f628 to check for a button press (this all works) and I have one pin set for High for a steady LED. I am trying to also have a second LED blink continuously while the main program keeps looping (checking for button presses. I am trying to use the blink LED:

main:
High LED5 ' Turn on LED connected to PORTB.0
Pause 1000 ' Delay for .5 seconds
Low LED5 ' Turn off LED connected to PORTB.0
Pause 1000


readbutton1:

Pause 30
Button bt1,0,40,0,B1,0,readbutton2
Toggle LED1 ' Toggle LED if pressed

readbutton2:
Button button2,0,40,0,B2,0,readbutton1
Toggle LED2 ' Toggle LED if pressed
goto readbutton1

If I have it return to main, then it blinks but the button checks are erratic. I am trying to get away from having a 555 timer in the circuit just to provide a blinking LED and was hoping something SIMPLE would work.
Any advice would be greatly appreciated.

What's the next chip up from F627/8 for basic digilal I/O? Need a few more pins.

$
0
0
Most of the designs I have done recently have used the F627/8 chips using mostly digital I/O and one or two analog inputs, but now I need two or three more digital I/O pins and I'm trying to figure out which is the least expensive, simplest chip that just has a little more I/O. I am looking at the 16F631/677/685/689/690 series and these look like good cost/performance choices. Just wondering if anyone else has gone here before and has a preferred chip. It is so baffling drilling down through Digi-Key's search table. I don't want to go through the process of learning a whole new chip only to find it has limitations or issues.

My current project involves a custom-designed static LCD where I'm going to direct drive the segments from the port pins. So I am up 15 I/O pins (plus backplane drive) for the LCD and need the extra pins for user interface.

EUSART's - Which timers do they use?

$
0
0
Referencing page 12 of the 18F87J50 data sheet, the diagram has arrows pointing from EUSART1 to Timer3 and EUSART2 to Timer4. Is that true? If not, which timers are they associated with?

For now, I need to use a pause in a timer. I know you're not supposed to do that and will remove it when the code gets refined later on. The main reason for asking the question is that when there's a long pause in Timer3 and/or Timer4, the data for HSERIN and HSERIN2 sometimes aren't received.

If I use a pause in any timer, will the HSERIN data always be affected?

18F25K20 osc setting problem

$
0
0
Hi every one,

On a older application with the 18F25K20 I need some more I/O. So, I remove the crystal to get RA6 and RA7 available.

Now I want to switch to the internal osc and try this working with @_CONFIG_CONFIG1H_FOSC_INTIO67 but nothing happend.

OSCCON = % 01110000 ' set to 8MHz
OSCTUNE = % 00000000 ' set PLL off

For control I connect a LED to a I/O. When I put the crystal back, the LED is flashing...

The software is written in Pro 2.60C and MPASM is using.

In MicroCode Studio Plus the Device set to PIC18F25K20 and the compiler give no errors.

Low power sleep mode 18f46k80

$
0
0
Hi guys trying to get the PIC to go to sleep in the lowest power mode available

but i notice even in sleep mode i am still pulling 3ma

also that the outputs with week pullups are still active on outputs
wondering if this normal even when in sleep mode
or have missed a setting

cheers

Sheldon


Code:

' config for 18F46K80
 
    #CONFIG

;----- CONFIG1L Options --------------------------------------------------
    CONFIG XINST    = OFF
    CONFIG SOSCSEL  = DIG        ; Digital (SCLKI) mode; I/O port functionality of RC0 and RC1 is enabled
    CONFIG INTOSCSEL = HIGH      ; LF-INTOSC in High-power mode during Sleep
    CONFIG RETEN    = ON        ; regulator is Enabled  (Controlled by SRETEN bit)when in sleep

;----- CONFIG1H Options --------------------------------------------------
    CONFIG IESO      = OFF
    CONFIG FCMEN    = OFF
    CONFIG PLLCFG    = ON
    CONFIG FOSC      = INTIO2    ; Internal RC oscillator  , PORTA.6 , PORTA.7 as I/O
 
;----- CONFIG2L Options --------------------------------------------------
    CONFIG BORPWR    = ZPBORMV    ; ZPBORMV instead of BORMV is selected
    CONFIG BORV      = 2          ; 2V
    CONFIG BOREN    = SBORDIS    ; Enabled in hardware, SBOREN disabled
    CONFIG PWRTEN    = OFF

;----- CONFIG2H Options --------------------------------------------------
    CONFIG WDTPS    = 512        ; 1:512
    CONFIG WDTEN    = OFF        ; WDT off
 
;----- CONFIG3L Options --------------------------------------------------
; no register in the device

;----- CONFIG3H Options --------------------------------------------------
    CONFIG MCLRE    = ON              ; MCLR ENabled FOR DIAG , RG5 DISabled
    CONFIG MSSPMSK  = MSK7            ; 7 Bit address masking mode
    CONFIG CANMX    = PORTB          ; ECAN TX and RX pins are located on RB2 and RB3, respectively

;----- CONFIG4L Options --------------------------------------------------
    CONFIG BBSIZ    = BB1K            ; 1K word Boot Block size
    CONFIG STVREN    = ON

;----- CONFIG5L Options -------------------------------------------------- 
   
    CONFIG CP0      = ON        ;  MEMORY BLOCK 0 CODE PROTECT BIT - 7KW 800h  - 3FFFh ( when 1K BOOT OPTION used )
    CONFIG CP1      = ON        ;  MEMORY BLOCK 1 CODE PROTECT BIT - 8KW 4000h - 7FFFh
    CONFIG CP2      = ON        ;  MEMORY BLOCK 2 CODE PROTECT BIT - 8KW 8000h - BFFFh
    CONFIG CP3      = ON        ;  MEMORY BLOCK 3 CODE PROTECT BIT - 8KW C000h - FFFFh
 
 
;----- CONFIG5H Options -------------------------------------------------- 
  CONFIG  CPD      = OFF        ; EEPROM DATA PREOTECT BIT - EXTERNAL R/W
  CONFIG  CPB      = ON        ; BOOT BLOCK CODE PROTECT BIT

;----- CONFIG6L Options -------------------------------------------------- 
    CONFIG WRT0      = OFF      ; MEMORY BLOCK WRITE PROTECT BIT
    CONFIG WRT1      = OFF
    CONFIG WRT2      = OFF
    CONFIG WRT3      = OFF
 
 
;----- CONFIG6H Options -------------------------------------------------- 
    CONFIG WRTD      = OFF      ; EEPROM WRITE PROTECT BIT - INTERNAL AND EXTERNAL
    CONFIG WRTB      = ON      ; BOOT BLOCK WRITE PROTECT
    CONFIG WRTC      = ON      ; CONFIGURATION REGISTER WRITE PROTECT BIT
 
;----- CONFIG7L Options -------------------------------------------------- 
    CONFIG EBTR0    = OFF    ; MEMORY READ TABLE BLOCK PROTECT
    CONFIG EBTR1    = OFF
    CONFIG EBTR2    = OFF
    CONFIG EBTR3    = OFF
   
;----- CONFIG7H Options -------------------------------------------------- 
    CONFIG EBTRB    = OFF    ; TABLE READ PROTECT BOOT
 
  #ENDCONFIG

Code:


' =========== Power Shutdown routine ==================
Shut_Down:

 pwr_on = 1                              ' PWR ON = 1 = OFF  - turns off power to devices external to cpu
@ INT_DISABLE  RBC_INT                  ; TURN OFF PortB IOC Interrupts for RX_mode  - RF_IRQ pin NOT USED WHEN IR-TX       
@ INT_DISABLE  RX2_INT                  ; Turn Off  USART RX Interrupts for RX_mode  - RX input on USART not used when IR-TX for configuration
@ INT_DISABLE  TMR0_INT                  ; disable  Timer0 interupts and start Timer0


 INTCON.1 = 0                            ' CLEAR INT0 interupt flag prior to enable 
 PWR_shutdown = 0                        ' CLEAR shutdown flag
@ INT_ENABLE INT0_INT                    ; Enable INT0 interupt to allow wakeup from Sleep command  - Triggered by PWR_SW , active Low 
OSCCON.7 =0                            ' clear  IDLEN bit ready for sleep command
@ sleep                                  ; sleep command

 return

Interpret to Picbasic Code ¿?!!

$
0
0
Hello,

As I interpret this in Picbasic code:
It is for the IC MAX17040, Project GauGauge
Clearly are functions or subroutines.

The lines 111 and 123, I think are Subrutines.
The lines 117 and 118 , I think variable reg MSB,LSB
The lines 113 and 125, I think calls to chip
The lines 129 and 130, I think variable reg MSB,LSB

But the lines 114, 115 ,120 and 132 I don´t understand.

-------------------------------------------------------------
Code:


111 static void max17040_get_vcell(struct i2c_client *client)
112 {
113        struct max17040_chip *chip = i2c_get_clientdata(client);
114        u8 msb;
115        u8 lsb;
116
117        msb = max17040_read_reg(client, MAX17040_VCELL_MSB);
118        lsb = max17040_read_reg(client, MAX17040_VCELL_LSB);
119
120        chip->vcell = (msb << 4) + (lsb >> 4);
121 }
122
123 static void max17040_get_soc(struct i2c_client *client)
124 {
125        struct max17040_chip *chip = i2c_get_clientdata(client);
126        u8 msb;
127        u8 lsb;
128
129        msb = max17040_read_reg(client, MAX17040_SOC_MSB);
130        lsb = max17040_read_reg(client, MAX17040_SOC_LSB);
131
132        chip->soc = msb;
133 }
134

THX.

Question about SERIN / SEROUT and why I have to send commands twice?

$
0
0
I have an odd problem with SERIN and SEROUT in that to get them to work, I often times, if not always have to send my command to the receiving PIC or device twice in order to get any kind of action going.

I've had this problem in the past when I attached a PIC to a serial to alarm panel control bus converter. The device was supposed to let you connect some unspecified home automation widget to the alarm panel and it simply converted whatever serial commands to Superbus 2000 (whatever protocol that really is, I don't know, differential lines, I know that). The thing wanted to check in with whatever you had connected with it once every couple of seconds via an ACK /NAK back and forth if you weren't updating it with commands.

So I connected a PIC 16F648A to it rather than a home automation device just to play around. I only ever got around to having it reply with the required NAK every time it would query the PIC. But I would have to send the NAK twice to get it to work.

I recently have been using RealTerm to talk to a 18F2320 via a SERIN that looks like
Code:

SERIN PORTC.0,2,[*],W0,W1,W2
and as long as it sees the "*", it replies with an ACK. BUT I have to send every command from RealTerm Twice....

Is there something I'm missing? It's really kind of annoying. I know I can just double up the commands to make it work, but I don't think it's right and a waste of code space.

Thank you ahead of time for your thoughts and opinions.

I always make it a point to stress how important you guys are all to me. Even if you've never directly replied to my questions, I've probably read something of yours and it's help me out along the way. Even if you thought you were just asking a "dumb" question, I probably had that question at some point too, and therefore you've helped me. besides, there really are no dumb questions.

I really care about this forum and it's members - There's been a lot of guys that were on a whole 'nother plane of thinking about this stuff that either are no longer with us, or have moved on for whatever reason and that makes me sad. But I see a lot of people starting to fill those shoes, or who are still with us that make me proud to be a part of the community.

You're doing electronics and playing with microcontrollers, and no matter your level, that sorta automatically makes you smarter than the average bear! So be proud of yourself for that!

There's been some newer micro's (dev boards really) on the block that seem to get all the love these days. And while they are just a different tool, like any other, I honestly feel PICBASIC and PICs are where it's at and we should take pride in our community and help others whenever we can. And also be patient and understanding that electronics and microcontrollers are a pretty difficult subject to grasp, else everyone would be doing it!

So again, thank you for helping me, but thank you for helping all of us. You are awesome!

/rant

Temperature does not go below 0

$
0
0
IAM MAKING TEMPERATURE CONTROLLER USING ntc THERMISTOR FROM -10 DEGREE TO 50 DEGREE.BUT MY TEMPERATURE IS NOT GOING BELOW 0. PLS CHECK MY CODE AND GUIDE ME.THANKS

Code:


 DG1 VAR BYTE     
 DG2 VAR BYTE   
 DG3 VAR BYTE
 DIGIT VAR BYTE
 DG VAR BYTE
 COUNTT VAR BYTE
 
 NUMB VAR WORD
 N VAR WORD
 adval var word
 temp var word
 TEMPP VAR WORD
 
 ADCON1=%10000000
 adcon0=%00000101
 TRISA=1         
 TRISB=%00111000 
 TRISC=0         
 
 numb=0
 gosub mread
 'n=numb
 GOSUB DIGITCALC 
'-------------------------------------------------------------------------


 MAIN1:


 GOSUB DISPLAY
 
 IF PORTB.3=1 THEN MREAD
 
 IF PORTB.3=0 THEN MAIN
 
 
 
 
 GOTO MAIN1
 
 
 






'-------------------------------------------------------------------------
                    MAIN:


                        ADCON0.2=1 


                      GO:
                        IF ADCON0.2=1 THEN GO
   
                        adval.HIGHBYTE = ADRESH                 
                        adval.lowbyte = ADRESL
                        temp=adval
                        N=temp
                        gosub display
                        gosub digitcalc
                       
                       
                        If adval>NUMB then PORTB.7=0
                        IF ADVAL< NUMB-5 THEN PORTB.7=1
                        GOTO MAIN1




                    '_____________________________________


                    UP:
                    IF NUMB=50 THEN MAIN
                    NUMB=NUMB+1
                    N=NUMB
                    GOSUB DIGITCALC
                    IF PORTB.4=1 THEN MEMORY
                    GOTO MAIN1
                   
                   
                    memory:
                    WRITE 0,numb.HighByte   
                   
                    WRITE 1,numb.LowByte   
                   
                    GOTO MAIN1


                    '_____________________________________


                    DOWN:
                    IF NUMB=-10 THEN MAIN      'MIN LIMIT
                    NUMB=NUMB-1
                    N=NUMB
                    GOSUB DIGITCALC
                    IF PORTB.5=1 THEN MEMORY
                    GOTO MAIN1
                   
                   
                    '_____________________________________
                    MREAD:
                    READ 0,numb.HighByte   
                                                   
                    READ 1,numb.LowByte 
                   
                    n=numb
                    gosub digitcalc
                    IF PORTB.4=1 THEN UP
                    IF PORTB.5=1 THEN DOWN
                    goto main1
                   
                   
                   
                   
         
                   
                   
                   
                     
                     
                   
      ___________________________________________________
        DISPLAY:
       
       
        FOR COUNTT=0 TO 99


        PORTC=DG1
        PORTB.2=1
        PAUSEUS 300
        PORTB.2=0


        PORTC=DG2
        PORTB.1=1
        PAUSEUS 300
        PORTB.1=0


        PORTC=DG3
        PORTB.0=1
        PAUSEUS 300
        PORTB.0=0


        NEXT COUNTT


        RETURN


      '________________________________________________________________






'__________________________________________________________________________
DIGITCALC:


DIGIT=0
LP1:
IF N<100 THEN DS1
N=N-100
DIGIT=DIGIT+1
GOTO LP1
        DS1:
        GOSUB FND
        DG1=DG
     


DIGIT=0
LP2:
IF N<10 THEN DS2
N=N-10
DIGIT=DIGIT+1
GOTO LP2


        DS2:
        GOSUB FND
        DG2=DG
       


DIGIT=N
GOSUB FND
DG3=DG




 
RETURN








'__________________________________________________________________________




'__________________________________________________________________________
FND:








FND0:
IF DIGIT>0 THEN FND1
DG=$7E                      '%0111 1110     
GOTO FNDEND


FND1:
IF DIGIT>1 THEN FND2
DG=$48                      '%0100 1000     
GOTO FNDEND


FND2:
IF DIGIT>2 THEN FND3
DG=$3D                      '%0011 1101     
GOTO FNDEND


FND3:
IF DIGIT>3 THEN FND4
DG=$6D                      '%0110 1101     
GOTO FNDEND


FND4:
IF DIGIT>4 THEN FND5
DG=$4B                      '%0100 0011     
GOTO FNDEND


FND5:
IF DIGIT>5 THEN FND6
DG=$67                      '%0110 0111     
GOTO FNDEND


FND6:
IF DIGIT>6 THEN FND7
DG=$77                      '%0111 0111     
GOTO FNDEND


FND7:
IF DIGIT>7 THEN FND8
DG=$4C                      '%0100 1100     
GOTO FNDEND


FND8:
IF DIGIT>8 THEN FND9
DG=$7F                      '%0111 1111     
GOTO FNDEND


FND9:
DG=$6F                      '%0110 1111     


FNDEND:
RETURN

'_________________________________________________ _________________________

DS 3231 temperature reading

$
0
0
Hello everyone,
I made a clock with DS3231 chip and clock works great. Now I would like to have and temperature display with this chip but I do not know how to do that. Does someone have a sample program to calculate the temperature from it in the positive and negative values
Best regards Visnja

Suggestions for a 40 pin DIP PIC with two MSSP

$
0
0
Guys,

If you have been following my recent posts you'll see that I've been playing with an i2c adapter that allows a 128 x 64 GLCD to be driven by sending instructions via the i2c bus. Lets just say things haven't gone well, and it appears that I've given up with that board and may of damaged the glcd as well.

Anyway I'm looking at alternatives for this project. I can get a 128 x 64 GLCD for my easypic5 board (direct lug in) for around £14. However these are not supported by the i2c adapter board due to using a different chipset, so I would have to use the traditional parallel method of connection, which causes me a problem because this requires additional pins compared to the 20 x 4 LCD I'm using and I'm short on spare pins.

So, moving on, I've seen a 2.8" TFT which is not much more expensive than the stock 128 x 64 mono GLCD and touchsceen for the easypic5. Whilst it's pin for pin compatible with the parallel header on the EasyPic5 board, I can't use that due to the issue mentioned above. But it also has an SPI interface, which would make life simpler on the pin count. But then I need a PIC that has 2 MSSP's so I can use the i2c bus for other items such as the DS1307 RTC chip.

Anyone know of an 18F device in a 40 pin package that has two MSSP's that can be configured independently for the two protocols.

Not able to compile code due to PBPPROC.bal file not found

$
0
0
Hey All, I am relatively new to programming with the Picbasic Pro compiler and MPLAB IDE v.8.53. I am currently trying to compile some old code (C with inline assembly) on a windows 8.1 machine. I am trying to compile this for the 18F4520. When attempting to compile, I am getting the following error:

Code:

--------------------
Executing: "C:\PBP\PBPMPLAB.BAT" -p18F4520 -n -ampasmwin -k# "FILE.pbp"
Executing: "C:\PBP\PBPW.EXE" -p18F4520 -n -ampasmwin -k# "FILE.pbp"   
PICBASIC PRO(TM) Compiler 2.60LA, (c) 1998, 2009 microEngineering Labs, Inc.
All Rights Reserved.


ERROR: Unable to find -p<pic> processor file PBPPROC.BAL


PICBASIC PRO(TM) Compiler 2.60A, (c) 1998, 2010 microEngineering Labs, Inc.
All Rights Reserved.

----------------------

Note that there is a 18F4520.BAL file in the PBP directory, and there appears to be a .BAL, .BAS and .INC file for most processors. There is also a PBPPROC.BAS file and a PBPPROC.INC file but no PBPPROC.BAL file. The PBPPROC .BAS and .INC files both only contain this:

INCLUDE "16F84.BAS"

in the .bas file and

INCLUDE "16F84.INC"

in the .inc file.

Is there an easy solution to solve this? Can I make a .BAL file? Why wasn't this file in the directory when I installed PBP?

Thanks in advance!

Reading DS1620 (SPI Temperature) from 18F46k22 Micro at 16MHz

$
0
0
In the past I built a device that read the temperature from two DS1620 (SPI) using an 18F4620 at 8MHz and it has been working good for years. Recently I had some boards made for this design, however I used an 18F46k22 running at 16MHz instead. I am using shiftin/shiftout commands to read the temp. The speed difference in micros seems to be affecting the temp reading. I tried adding DEFINE SHIFT_PAUSEUS 100 to the code. I also added a small pause between the reading of Temp1 and Temp2. I played around with different SHIFT_PAUSEUS (1000, 2000, & 3000). Nothing seems to help. I am not sure if the timing is the problem, however I am just guessing at the values I am trying. Does anyone know what setting I should be using on the 18F46k22 running at 16MHz to make it as close to a 18F4620 running at 8MHz? Or any other suggestions?
Thanks,
Jim
Viewing all 4787 articles
Browse latest View live